2013年2月28日 星期四

在cron呼叫shell script時若有使用grep需注意時間格式

花了半天的時間,結果和一大早猜測的結果相同 ><,白白花了三個小時的時間....

在cron呼叫shell script時若有使用grep需注意時間格式

在shell裡的輸出:
-rwxr-xr-x  1 root   root      57 2013-03-01 14:29 cp_NTU.sh
-rw-r--r--  1 root   root    6593 2013-03-01 10:50 getdata.php
-rwxr-xr-x  1 root   root     507 2013-03-01 14:28 get_yesterday.sh
-rwxr-xr-x  1 root   root     155 2013-03-01 10:47 output.sh

在crontab裡呼叫時的輸出:
-rw-r--r--   1 root   root     6377 Mar 21  2012 08-circuit
-rw-r--r--   1 root   root     7647 Apr 10  2012 1
-rw-r--r--   1 root   root    27103 Mar 17  2012 11-3.cfg
-rw-r--r--   1 root   root     9873 Mar 17  2012 11-3.csv
-rw-r--r--   1 root   root  1419670 Mar 19  2012 139.175.235.83.txt

所以如果在cron呼叫shell script時若有使用grep需注意時間格式
例如:
/bin/ls -l --time-style="+%Y-%m-%d %H:%M:%S" /mnt/windump/NTU_old/NTU* | /bin/grep $yesterday | /bin/awk'{print "/bin/cp -p " $8 " /home/klting/NTU"}' > /home/klting/NTU/cp_NTU.sh

在ls -l的後面,要使用time-style,強制指定格式。

沒有留言:

張貼留言