[Original]Ubuntu Server痛苦的脚本调试 – tar
Ubuntu(我想应该包括debian)和RHEL的细微区别体现出来了,以下脚本在RHEL上执行没问题,
11 0 * * * tar -g /data0/snapshot_data_www -p cvzf /data1/backup_zone/data_www/data_www_`date ‘+%Y%m%d’`.tar.gz /data0/data_www #backup the data_www directory
在Ubuntu上,就屡次调试不过。经过调试,认为存在以下差异
1.Ubuntu的tar -g 不支持完整路径名;可以用变量取代之
2.Ubuntu的tar在cron中,不支持v(可视化)参数;可以不用,对备份没有影响
3.Ubuntu的tar在cron中,%符号有其他意义,代表命令换行;可以在前面加个\符号,将其变为转义字符。
最后的方案如下(已调试成功)
# crontab -l
# m h dom mon dow command
00 00 * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
28 23 * * * /etc/webmin/cron/tempdelete.pl
1 0 * * 1 find /data1/backup_zone/data_www/* -mtime +28 |xargs rm -f
10 00 * * 1 cat /dev/null > /data1/backup_zone/data_www/snapfile
11 00 * * * bash /root/script-bak/bak_www.sh
1 1 * * * bash /root/script-bak/bak_conf.sh
11 1 * * 1 find /data1/backup_zone/data_conf/* -mtime +28 |xargs rm -f
# more /etc/
Display all 183 possibilities? (y or n)
root@krc:~# more ~/script-bak/bak_www.sh
#!/bin/bash
#backup the data_www dictory
snap_file=/data1/backup_zone/data_www/snapfile
tar -g $snap_file -czf /data1/backup_zone/data_www/data_www_`date ‘+%Y%m%d’`.tar.gz /data0/data_www
P.S.Ubuntu默认不打开cron的log,需手工打开,并重启syylogd服务
#vim /etc/syslog.conf
cron.* /var/log/cron.log #将本行的前的注释符去掉
#/etc/init.d/sysklogd reload
监视脚本的执行情况,以便发现问题所在
# tail -f /var/log/cron.log
网上几篇文章,也是关于这个问题的讨论,悬而未决
1.http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?viewmode=compact&topic_id=11983&forum=2
最近评论