删除 crontab 行中的“root”:
* * * * * /usr/bin/flock -xn /var/lock/script.lock -c '/bin/bash /root/Dropbox/1.sh'
如果您需要 root 权限,请放入 root 用户的 crontab。
使用“root”,您还会在 syslog 或消息日志中发现错误。
当然要确保cron 守护进程正在运行:ps -ef | grep cron
添加:我已经通过简单的触摸文件(在 ubuntu 上)对其进行了测试:
contab 行:
* * * * * /usr/bin/flock -xn /var/lock/script.lock -c '/bin/bash ~/1.sh'
1.sh:
#!/bin/bash
touch /tmp/hallo
添加:(查看 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 上的正则表达式。您的 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