crontab is not working!!

I can run manually script of ntopdump.sh but crontab can't run this script very five minutes.

# crontab -l
*/3 * * * * root sh /root/ping.sh
*/5 * * * * root sh /root/ntopdump.sh
# 
# pwd
/root
# ls -l
total 88
-rwxrwxr-x 1 root root  1645 Jun 14 19:01 anaconda-ks.cfg
drwxrwxr-x 2 root root  4096 Jun 14 16:05 Desktop
-rwxrwxr-x 1 root root 42604 Jun 14 19:01 install.log
-rwxrwxr-x 1 root root  5077 Jun 14 19:00 install.log.syslog
-rw-r--r-- 1 root root    14 Aug 26 17:20 IPADDR.txt
-rwx--x--x 1 root root   102 Aug 26 17:20 ntopdump.sh
-rwx--x--x 1 root root    53 Aug 26 17:20 ping.sh
# 
# cat ntopdump.sh 
wget -O ntop-$(date +%Y%m%d_%H:%M).php "http://127.0.0.1:3000/dumpData.html?language=php&view=short"
#

what is your crontab log says ?

check in /var/log/

Everthing seems fine ? isn't it? Time priod is right. There is no error messages.
I added !/bin/bash first line of this script but reason didn't change.

# tail -f  /var/log/cron
Sep  7 13:20:01 argela crond[17306]: (root) CMD (root sh /root/ntopdump.sh)
Sep  7 13:21:01 argela crond[17314]: (root) CMD (root sh /root/ping.sh)
Sep  7 13:24:01 argela crond[17324]: (root) CMD (root sh /root/ping.sh)
Sep  7 13:25:01 argela crond[17332]: (root) CMD (root sh /root/ntopdump.sh)
Sep  7 13:25:39 argela crontab[17339]: (root) LIST (root)
Sep  7 13:27:01 argela crond[17347]: (root) CMD (root sh /root/ping.sh)
Sep  7 13:30:01 argela crond[17358]: (root) CMD (root sh /root/ntopdump.sh)
Sep  7 13:30:01 argela crond[17359]: (root) CMD (root sh /root/ping.sh)
Sep  7 13:33:01 argela crond[17396]: (root) CMD (root sh /root/ping.sh)
Sep  7 13:35:01 argela crond[17441]: (root) CMD (root sh /root/ntopdump.sh)

What is the main problem.!!!!!!!!!!!! :confused:

# cat ntopdump.sh 
!/bin/bash
wget -O ntop-$(date +%Y%m%d_%H:%M).php "http://127.0.0.1:3000/dumpData.html?language=php&view=short"
# 
#!/bin/bash

Is this typo ?

!/bin/bash -- Missing #

My friends, script isn't working on crontab but it is working manually.

Everythink seems fine but what is the problem!

If it isn't the missing # at the start of the shebang line then it could be that wget isn't on crontab's path.
try substituting the full path to the wget binary

Does your script rely on relative path names or other things that require a path? Items in cron do not get a full environment and thus need to have their variables defined more rigorously or source an environment script.

Also, how are you executing the script manually? Is there an x bit set for the user in cron?

Try it like this:

*/3 * * * * /root/ping.sh > /tmp/ping.log 2>&1
*/5 * * * * /root/ntopdump.sh > /tmp/ntopdump.log 2>&1

This will redirect stdout and stderr to those 2 log files. There should be hopefully some message in them.
Also you might want to leave out the extra sh as you start a new shell anyway, with #!/bin/bash a bash, as you wrote. What's the leading "root" for?

Also in a script being issued via cron you should always use absolute paths like:

/usr/bin/wget ....

While I write this - just as people said.

There is also a good article about usage of crontab in this forum you should read:

1 Like
# cat /root/ntopdump.sh 
#!/bin/bash
/usr/bin/wget -O ntop-$(date +%Y%m%d_%H:%M).php "http://127.0.0.1:3000/dumpData.html?language=php&view=short"
# 

I am wondering a lot why script is not working or crontab.!!!!

Let me guess, you assume it's not working because you don't see a ntop-* file anywhere in your home directory, right? That's because cron doesn't execute your script in your home directory, but in an empty temporary directory.

Tell wget to save to an absolute path, instead of a relative, and you should see your file.

Also, you CAN NOT put the shebang (#!/bin/bash) on the second line. IT MUST be the first line and the first character of that line.

# crontab -l
*/3 * * * * root sh /script/ping.sh >> /tmp/ping.log 2>&1
*/5 * * * * root sh /script/ntopdump.sh >> /tmp/ntopdump.log 2>&1
#
# tail -f /tmp/ntopdump.log 
/bin/sh: root: command not found
/bin/sh: root: command not found
/bin/sh: root: command not found
/bin/sh: root: command not found
/bin/sh: root: command not found
/bin/sh: root: command not found

root is not command only user!!!!
schema of the crontab picture is attached.
I have deleted root parameter from crontab and it is done. :b:

I have changed crontab line like below but it gave same error message.

# crontab -l
*/3 * * * * root /script/./ntopdump.sh > /tmp/ntopdump.log 2>&1
# 

Why root is a problem for this scenario or this redhat-release of RHEL 5.5

---------- Post updated at 05:44 PM ---------- Previous update was at 05:42 PM ----------

picture

picture is attached

You only specify usernames for /etc/crontab, not user crontabs.