SaltyDawg
asked on
Cron Job using Crontab
I need to create a cron job that executes a file every morning at 4am. I have need used cron jobs before so pretty much lost right. I've read alot of things but still not sure. Can someone give me a step by step help from the very begining.
I am not sure how to access the crontab or write to it.
I need to run this file every morning at 4am.
/crons/mysql/update.sh
I use 'crontab -e' then try to add '00 04 * * * /crons/mysql/update.sh' to the line it says 'Crontab: no crontab - using an empty one'
I then tried adding '00 04 * * * /crons/mysql/update.sh' then says 'isn't a vi command'
What do I do?
Thanks
This is what I Have so far
I am not sure how to access the crontab or write to it.
I need to run this file every morning at 4am.
/crons/mysql/update.sh
I use 'crontab -e' then try to add '00 04 * * * /crons/mysql/update.sh' to the line it says 'Crontab: no crontab - using an empty one'
I then tried adding '00 04 * * * /crons/mysql/update.sh' then says 'isn't a vi command'
What do I do?
Thanks
This is what I Have so far
Or, you can change your default editor like :
Let say your prefered editor is nano (pico), or whatever...
Do this:
EDITOR=nano
export EDITOR
then crontab -e will open the crontab in nano.
Let say your prefered editor is nano (pico), or whatever...
Do this:
EDITOR=nano
export EDITOR
then crontab -e will open the crontab in nano.
crontab -l > crontab.txt
edit crontab.txt file
add line to this file:
0 4 * * * /crons/mysql/update.sh
save the file
run:
crontab crontab.txt
I think your problem is vi related. It looks, that your are not saving this file (are you quitting with :q! command from vi editor? If so, try :wq or :wq! command). However above method (crontab -l > ...; editing file; crontab this.file should work).
edit crontab.txt file
add line to this file:
0 4 * * * /crons/mysql/update.sh
save the file
run:
crontab crontab.txt
I think your problem is vi related. It looks, that your are not saving this file (are you quitting with :q! command from vi editor? If so, try :wq or :wq! command). However above method (crontab -l > ...; editing file; crontab this.file should work).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
omarfarid:
When I use your code it says:
'crontab: non crontab for user
?
When I use your code it says:
'crontab: non crontab for user
?
ASKER
I think I have it now
ASKER
Thanks
welcome :)
enter "crontab -e" on a command line, which will either 1) Open you current cron file in vi, or 2) open an empty new file in vi
Use the arrow keys to go to the last line in the file, if there are any, then press "A" (that's a capital A, no quotes) - this takes VI out of command mode and into edit mode (specifically the A tells VI to append to the end of the current line)
Press enter to go to the next line down, and enter your cron job schedule "00 04 * * * /crons/mysql/update.sh"
Then press the Esc key to go back into command mode, then type :wq! (the colon goes to VI's command prompt, the w means write the file, the q means quit and the exclamation point means don't ask for confirmation).