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
阅读(2085) | 评论(0) | 转发(0) |