crontab无法使用bash的build-in函数
[
|
2010/02/04 11:14]
|
2010/02/04 11:14]
操作系统:Debian cat /etc/debian_version squeeze/sid
事情这样地,写了一个脚本,里面有bash的内建命令,有for循环之类的。使用的时候发现无法执行。如果去掉for循环,直接执行命令,就OK,我就奇怪这是为什么?
仔细的查了一下,发现了原因。
ha01:~/bin# grep -v ^# /etc/crontab
MAILTO=root
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
ha01:/bin# ls -al /bin/sh
lrwxrwxrwx 1 root root 4 12月 1 12:45 sh -> dash
原因已经确认,debian默认crontab里面用的是dash而不是shell,那修改也就简单了。
ha01:~# rm /bin/sh
ha01:~# ln -s /bin/bash /bin/sh
事情这样地,写了一个脚本,里面有bash的内建命令,有for循环之类的。使用的时候发现无法执行。如果去掉for循环,直接执行命令,就OK,我就奇怪这是为什么?
仔细的查了一下,发现了原因。
ha01:~/bin# grep -v ^# /etc/crontab
MAILTO=root
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
ha01:/bin# ls -al /bin/sh
lrwxrwxrwx 1 root root 4 12月 1 12:45 sh -> dash
原因已经确认,debian默认crontab里面用的是dash而不是shell,那修改也就简单了。
ha01:~# rm /bin/sh
ha01:~# ln -s /bin/bash /bin/sh



