ESXi uses the cron to schedule several internal housekeeping routines. In some instances, new cron jobs may need to be added to the ESXi host. However, they won't be persistent after rebooting by default.
vSphere ESXi
Cron jobs on ESXi hosts do not persist across reboots without manual edits of the local.sh
script file.
First, make a backup of the current root crontab file:
cp /var/spool/cron/crontabs/root /var/spool/cron/crontabs/root.old
Add the desired cron job to the root crontab:
vi /var/spool/cron/crontabs/root
In the editor, add your cron job with the required schedule and command.
/etc/rc.local.d/local.sh
FileTo ensure the cron job is re-created upon reboot, follow these steps:
vi /etc/rc.local.d/local.sh
At the end of the file, add the following lines:
/bin/kill $(cat /var/run/crond.pid) /bin/echo '5 0 * * * /full/path/to/script arguments/with/full/path > /full/path/to/logfile 2>&1' >> /var/spool/cron/crontabs/root /usr/lib/vmware/busybox/bin/busybox crond
Press the following keys to save and exit:
Run this command to ensure that the changes to /etc/rc.local
are persistent across reboots:
auto-backup.sh
Every time the cron job is modified, ensure that /etc/rc.local.d/local.sh
is updated and run the auto-backup.sh
command to back up the changes.
Cleaning up & restoring:
/var/spool/cron/crontabs/root
& remove cron job entrycrond
using busyboxlocal.sh
filecp /scratch/downloads/local.sh.original /etc/rc.local.d/local.sh
local.sh.<TimeStamp>
if anyauto-backup.sh