2012-11-01 128 views
0

我的cron的Cron不運行bash腳本

SHELL = /斌/慶典

PATH =在/ usr/local/sbin中:在/ usr/local/bin目錄:/ sbin目錄:/ bin中:/ usr/sbin目錄:在/ usr/bin中

* * * * * root /usr/bin/flock -xn /var/lock/script.lock -c '/bin/bash /root/Dropbox/1.sh' 

我1.sh

#!/bin/bash -l 

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 

x=1 
while [ $x -le 3 ] 
do 
URL=$(head -n 1 /root/Dropbox/query.txt) 
lynx -dump $URL | egrep '^http' > /root/Dropbox/urls.txt 
x=$(($x + 1)) 
done 

bash作爲默認

#回聲$ SHELL

/斌/慶典

的cron爲什麼不運行1.sh?

回答

1

刪除 「根」 在crontab中一行行:

* * * * * /usr/bin/flock -xn /var/lock/script.lock -c '/bin/bash /root/Dropbox/1.sh' 

如果你需要把根用戶的crontab root用戶權限。
使用「root」時,您還會在系統日誌或消息日誌中發現錯誤。

當然可以肯定cron守護進程正在運行:ps -ef | grep的cron的

地址:
contab線: 我用簡單的觸摸一個文件(在Ubuntu)測試它

* * * * * /usr/bin/flock -xn /var/lock/script.lock -c '/bin/bash ~/1.sh' 

1.sh:

#!/bin/bash 
touch /tmp/hallo 

地址:(看着l command命令) 1.sh腳本的一個版本適用於我。

#!/bin/bash 

x=1 
while [ $x -le 3 ] 
do 
URL="http://www.subir.com/lynx.html" 
lynx -dump $URL | egrep '.*\. http' > urls.txt 
x=$(($x + 1)) 
done 

我更改了egrep上的regEx。您的l output輸出可能不同(其他版本的l))。我使用了一個固定的測試URL(lynx手冊頁)。 urls.txt將被填充。腳本由cron觸發。在下一次運行中,循環邏輯中的注意事項將會改變。

[email protected]:~$ more urls.txt 
    1. http://lynx.isc.org/current/index.html 
    2. http://lynx.isc.org/current/lynx2-8-8/lynx_help/lynx_help_main.html 
    3. http://lynx.isc.org/current/lynx2-8-8/lynx_help/Lynx_users_guide.html 
    4. http://lynx.isc.org/lynx2.8.7/index.html 
    5. http://lynx.isc.org/lynx2.8.7/lynx2-8-7/lynx_help/lynx_help_main.html 
    6. http://lynx.isc.org/lynx2.8.7/lynx2-8-7/lynx_help/Lynx_users_guide.html 
    7. http://lynx.isc.org/mirrors.html 
    8. http://lists.nongnu.org/mailman/listinfo/lynx-dev/ 
    9. http://lynx.isc.org/signatures.html 
    10. http://validator.w3.org/check?uri=http%3A%2F%2Flynx.isc.org%2Findex.html 
+0

cron守護程序正在運行。我把1.sh cat,grep或wget -cron運行1.sh我認爲變量$ URL或$ x有問題,可能是cron不能正確理解它。我在cron中沒有root測試 - 沒有運行。 – Alex

+0

如果cron已經啓動了1.sh腳本,那麼cron會完成這項工作。 1.sh中的while循環通常也可以。不確定URL和lynx行。你能通過cron運行另一個腳本嗎?你可以手動運行1.sh腳本嗎? – derlinuxer

+0

是的我在控制檯中手動運行腳本沒有問題。沒有l and,沒有$ URL,$ x - 它從cron – Alex