Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15358467
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2010-03-24 15:36:35

linux下自动将shell执行结果发送mail邮件的脚本

#!/bin/sh
mail='luther@gliethttp.cn'
mail_cc=''
log_file='/tmp/luther.gliethttp.autoscript.log'
exec 1>$log_file
exec 2>&1

if [ `id -u` -eq 0 ]; then
    muttrc='/vobs/config_repos/mail/muttrc_root'
else
    muttrc='/vobs/config_repos/mail/muttrc'
fi


#==压缩备份文件============================================
>$log_file
cmd="tar jcvf /vobs/bak_storage/`date +%y%m%d%H%M%S_trac_svnrepos_configs.tar.bz2` trac svn_repos configs "
echo "==命令==================="
date
echo "$cmd"
echo "========================="
cd /vobs
$cmd
result=$?
cd -
date

if [ $result -eq 0 ]; then
    mutt -F $muttrc -s "成功:$cmd" $mail < $log_file
else
    mutt -F $muttrc -s "失败:$cmd" $mail < $log_file
fi

#==rsync备份文件============================================
>$log_file
cmd="rsync -avhlpxxE --delete /vobs/ /2vobs/vobs"
echo "==命令==================="
date
echo "$cmd"
echo "========================="
$cmd
result=$?
date

if [ $result -eq 0 ]; then
    mutt -F $muttrc -s "成功:$cmd" $mail < $log_file
else
    mutt -F $muttrc -s "失败:$cmd" $mail < $log_file
fi

#==rsync远程备份文件============================================
>$log_file
cmd="rsync -avhlpxxE --delete /vobs/ luther@192.168.1.1:/vobs"
echo "==命令==================="
date
echo "$cmd"
echo "========================="
$cmd
result=$?
date

if [ $result -eq 0 ]; then
    mutt -F $muttrc -s "成功:$cmd" $mail < $log_file
else
    mutt -F $muttrc -s "失败:$cmd" $mail < $log_file
fi
阅读(2047) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~