Link to home
Start Free TrialLog in
Avatar of SaltyDawg
SaltyDawgFlag for United States of America

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
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Check out "man vi" for some info on using the VI editor.  If you have X windows installed there might be a GUI application...never used one though, so I'm not sure.

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).
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.
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).
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SaltyDawg

ASKER

omarfarid:

When I use your code it says:

'crontab: non crontab for user
?
I think I have it now
Thanks
welcome :)