I've created a cron job in AWS EC2 but it is not working.
I followed below steps to create cron tab:
Step 1: I logged in to AWS EC2 Instace
step 2: sudo su
step 2: crontab -e
Step 3: Insert mode
Step 4: I entered
# M H DOM M DOW CMND
15 14 * * 3 /services/backup.sh >/tmp/error.log 2>&1
Step 5: :wq Cron tab is created but not running.
Please can you any one help me , why it is not working?
UPDATE :
after lots of researching i found that i can give a log to the particular cron file so added >/tmp/error.log 2>&1 in my file and created error.log there.
but i am not getting any cron log there. now i think my cron file is not running(obviously it is not running).
but how to see whether i am lacking
and when i checked cron service it is running with the name crond
service crond status
crond (pid 28283) is running...
(backup.sh script absolutely running fine)
could you try full path of backup.sh in cron like below; you can use pwd command to find full path of your script.
# M H DOM M DOW CMND
25 12 * * 3 /home/user/script/backup.sh
Maybe, your cron service not started, you can check status with "ps -ef | grep cron | grep -v grep"
if not see any thing run this;
sudo service cron start
if run; change cron as below;
15 13 * * 3 root /fullpath/backup.sh >/tmp/error.log 2>&1
then you check error.log
>/tmp/error.log 2>&1 is; redirect the output of your program to /tmp/error.log. Include both the Standard Error and Standard Out
I think your issue might with permission and ownership of your backup.sh
file.
Check the ownership of file and then do changes accordingly in your /etc/crontab
file :
25 12 * * 3 <owner of the file> /home/user/script/backup.sh
For example if the owner of file backup.sh
is root
then it should look something like this:
25 12 * * 3 root /home/user/script/backup.sh
Hope this help!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.