Learning Crontab
Hi All,
I have added my first cron job like this: user@krishnar6:~$ crontab -l | grep -v "#" * * * * * /home/user/test.sh user@krishnar6:~$ cat /home/user/test.sh #!/bin/bash echo hello! user@krishnar6:~$ I expected this job to run every minute and print hello output. But it never did. Can you please help me to fix the prob? Krish |
The script will print to stdout, which cron sends to the configured email account.
Unless you have configured that in a sensible way you will never see it. Try redirecting the output to a file: Code:
#!/bin/bash Code:
chmod +x /home/user/test.sh |
Quote:
|
I have modified my scrip like this:
user@krishnar6:~$ cat test.sh #!/bin/bash echo hello! > crontest.txt mkdir /home/user/cron The cron job creates the text file but NOT the folder. I am wondering why folder is not getting created. |
Hmm, if all of this is happening as the same user this should actually work.
You can debug this by printing the output to a file. Change the crontab entry to Code:
* * * * * /home/user/test.sh > /tmp/crontab.out 2>&1 Please post the content of /tmp/crontab.out after an (unsuccessfull) cron execution. |
user@krishnar6:~$ cat /tmp/crontab.out
/home/user/test.sh: line 3: mkdir: command not found user@krishnar6:~$ |
Quote:
Run Code:
which mkdir That is the full path to mkdir. Use that in the script. So e.g.: Code:
/bin/mkdir /home/user/cron |
Thanks! That fixed the issue.
|
All times are GMT -5. The time now is 12:57 PM. |