On ESXi, changes to the cron configuration do not persist through a reboot. You must configure the cronjob and then add it to the startup scripts to ensure it survives a reboot.
1. Configure the Cronjob
Append the cron line to /var/spool/cron/crontabs/root. If you cannot edit it directly, create a backup, edit the copy, and move it back:
cp /var/spool/cron/crontabs/root /var/spool/cron/crontabs/root.backup
# [Edit root.backup with your cron line]
mv /var/spool/cron/crontabs/root.backup /var/spool/cron/crontabs/root
2. Restart the Cron Daemon
You must restart crond for changes to take effect. The command depends on your ESXi version:
- ESXi 5.1 to 6.x:
kill $(cat /var/run/crond.pid) && crond - ESXi 7.x and later:
kill $(cat /var/run/crond.pid) > /dev/null 2>&1 && /usr/lib/vmware/busybox/bin/busybox crond
3. Ensure Persistence via /etc/rc.local
Add the commands to recreate the cronjob to /etc/rc.local (or /etc/rc.local.d/local.sh on ESXi 5.1). This ensures the cronjob is re-added upon reboot.
For ESXi 7.x and later, add these lines to /etc/rc.local:
/bin/kill $(cat /var/run/crond.pid) > /dev/null 2>&1
/bin/echo "0 0 * * 1-5 /vmfs/volumes/path/to/ghettoVCB.sh -f /vmfs/volumes/path/to/backuplist > /vmfs/volumes/path/to/ghettoVCB-backup-\$(date +\\%s).log" >> /var/spool/cron/crontabs/root
/usr/lib/vmware/busybox/bin/busybox crond
4. Save ESXi Configuration
After modifying /etc/rc.local, run the following to save the state to the bootbank:
/sbin/auto-backup.sh
# Example for ESXi 7.x persistence in /etc/rc.local
/bin/kill $(cat /var/run/crond.pid) > /dev/null 2>&1
/bin/echo "0 0 * * 1-5 /vmfs/volumes/simplejack-local-storage/ghettoVCB.sh -f /vmfs/volumes/simplejack-local-storage/backuplist > /vmfs/volumes/simplejack-local-storage/ghettoVCB-backup-\$(date +\\%s).log" >> /var/spool/cron/crontabs/root
/usr/lib/vmware/busybox/bin/busybox crond