shell script可以手動執行但在crontab中無法執行

  

直接執行test.sh均可正常在aaa.txt輸出route結果,如圖一。但如果在crontab中建*/1 * * * * /root/test.shroutecommand便只有空空如也只有最下一行的date有輸出到aaa.txt,如圖二。

 

test.sh

test1=$(route)

echo "$test1" > aaa.txt

echo "#`date`" >> aaa.txt

 

解法為第一列加入export  PATH=/bin:/sbin:/usr/bin:/usr/sbin

成為test.sh

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

test1=$(route)

echo "$test1" > aaa.txt

echo "#`date`" >> aaa.txt

 

圖一

 

圖二

arrow
arrow
    全站熱搜

    adamschen9921 發表在 痞客邦 留言(0) 人氣()