VMware Cloud Community
Mahoushi
Contributor
Contributor

Crontab in ESX server

I made this script to backup my VMs to a tape device, ran it, works perfectly (though it takes a little time to compress the files), but then when I want to add it to automatically run this script once per day I go and type:

\# crontab -e

then I write the needed info to make my script run everyday at 20:00 but it wont run at that time... (wont run at all unless I manually run it).

Anything that I am missing? maybe I should have configured my ESX in some way to make cron work?

Any help appreciated.

Reply
0 Kudos
8 Replies
murreyaw
Enthusiast
Enthusiast

Use the cron.daily stuff, rather than root's individual crontab.

Reply
0 Kudos
admin
Immortal
Immortal

No configuration to make cron work and no problem with using roots cronttab, it's probably just a syntax error, can you post the contents of your cronttab file?

Reply
0 Kudos
Mahoushi
Contributor
Contributor

Mmm yah I said everyday, really meant every weekday (Monday - Friday).

I am not sure its a syntax error, in any case I just copied and pasted the result from my "pwd" command. I looks like this now:

0 20 * * 1-5 /vmfs/volumes/that_big_string_of_numbers_and_characters/backup_script_dir/my_backup_script

Reply
0 Kudos
bertdb
Virtuoso
Virtuoso

wouldn't it be better to put your backup script in /usr/local/bin or in /root/bin rather than in your vmfs ?

You can check whether the cron daemon started your script or not by looking at /var/log/cron

That way, you can eliminate script errors (first make sure cron starts the script, then make sure your script does its job)

msgertz
Enthusiast
Enthusiast

You may also want to redirect your output and errors to a file as follows:

00 01 * * 0-6 /usr/local/bin/AllBkup > /tmp/AllBkup.log 2>&1

This helps when you are having problems in a script. I also agree that your script should go in a script directory like /usr/local/bin.

DFATAnt
Enthusiast
Enthusiast

I have a similar problem. I have a script located in /root that runs fine when I run it manually. When I use crontab to run it, the script doesn't work. If I move the script to /tmp and use crontab to execute it, the script runs. I am wondering what I am missing.

Ant

Reply
0 Kudos
Henry_T_
Enthusiast
Enthusiast

Mahousihi,

the problem could be that the crontab doesn't run \{HOMEDIR}/.bashrc and /etc/bashrc. these are the 'autoexec' when you login. For example it has the aliasses for rm (alias rm='rm -i') you're PATH is set.

What you could do is start your script with:

. /etc/bahrsrc

Than all the variables will be known to the script.

if you don't use logging look in the mail from the user where you're crontab resides

Hope this helps!

regards Henry T.

Reply
0 Kudos
Mahoushi
Contributor
Contributor

Well, I found out that cron waits until the minute change to actually reload, so my "cron tests" never ran >.<

Anyway after I figured that out I managed to see that there was a path error in the script log files (no wonder I wasn't finding them). With the logs at hand I managed to correct the problem of the script. Also, I moved it to /root/script_directory and it seems to run pretty well now.

Thanks all Smiley Happy

Reply
0 Kudos