首页 文章

Cron不运行bash脚本

提问于
浏览
0

我有cron

SHELL = / bin / bash 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是默认的

#echo $ SHELL

/斌/庆典

为什么cron不运行1.sh?

1 回答

  • 1

    删除行crontab行中的“root”:

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

    如果需要root权限放在root用户的crontab中 .
    使用"root",您还会在syslog或消息日志中发现错误 .

    当然要确保 cron daemon is running :ps -ef | grep cron

    ADD:我用简单的触摸文件测试了它(在ubuntu上):
    接触线:

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

    1.sh:

    #!/bin/bash
    touch /tmp/hallo
    

    ADD :(查看lynx命令)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 . lynx的输出可能不同(其他版本的lynx) . 我使用了一个固定的测试URL(lynx手册页) . urls.txt将被填充 . 脚本由cron触发 . while将没有效果注意循环逻辑将在下次运行时更改 .

    stephan@coppi:~$ 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
    

相关问题