2012-11-01 133 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