Reputation: 1447
I have 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'
my 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 as default
# echo $SHELL
/bin/bash
Why cron doesn't run 1.sh ?
Upvotes: 0
Views: 2420
Reputation: 574
remove "root" in line crontab line:
* * * * * /usr/bin/flock -xn /var/lock/script.lock -c '/bin/bash /root/Dropbox/1.sh'
If you need root rights put in crontab of root user.
With "root" you will also find error in syslog or messages logs.
And of course be sure the cron daemon is running: ps -ef | grep cron
ADD:
I've tested it with simple touch a file (on ubuntu):
contab line:
* * * * * /usr/bin/flock -xn /var/lock/script.lock -c '/bin/bash ~/1.sh'
1.sh:
#!/bin/bash
touch /tmp/hallo
ADD: (looking at lynx command) A version of 1.sh Script it works for me.
#!/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
I changed the regEx on egrep. Your output of lynx may be different (other version of lynx). And I used a fixed test URL (lynx man page). The urls.txt will be filled. Script is triggered by cron. The while will have no effect noting in loop logic will be change on next run.
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
Upvotes: 1