VMware Cloud Community
MarcusHO
Contributor
Contributor

Simple SH script started with cron job, will not persist and settings/files are deleted after reboot.

Hello,

I created a simple little script to do a rescan of the storage adapters on the server, 60 seconds after boot.

I created a file called hbascan.sh and in that file i have this line "sleep 60s;esxcli storage core adapter rescan --all"

I placed this script in the /bin folder on the ESXi host

I edited the "/var/spool/cron/crontabs/root" in here i added "@reboot sh /bin/hbascan.sh" at the end/bottom of the file.

I then killed the Cron job after finding the correct ID

I then edited the "/etc/rc.local/" and added at the end of the file 3 rows with text.

/bin/kill $(cat /var/run/crond.pid)

/bin/echo '@reboot sh /bin/hbascan.sh' >> /var/spool/cron/crontabs/root

/bin/busybox crond

I saved the file and ran the command "sh /sbin/auto-backup.sh"

Problem is that when i reboot the server everything is gone, the script is gone and the changes to root and rc.local is also gone.

I did the edit of the files with winscp as i am not really confident in "vi"

I am not entirely sure what's wrong, it could be syntax or maybe file rights?

I followed a guide for this online and it's almost identical to the guide, only i did not provide any path to logs.

Any help would be greatly appreciated.

/Hyper-lost

Tags (3)
Reply
0 Kudos
2 Replies
DanJGF
Contributor
Contributor

The ESXi file system is not persistent, except for the /scratch partition, which typically is vfat, 4GB in size and is used to store logs and temp data.

# df -h

...

vfat         4.0G 135.8M      3.9G   3% /vmfs/volumes/735367abc...

Create a dir there

mkdir /scratch/myscripts to place your scripts and run them from this location

Reply
0 Kudos
aigarsk
Contributor
Contributor

Have a look in following link: https://virtuallyvtrue.com/2019/03/29/shell-script-to-automatically-power-on-a-specific-vm-which-is-...

I was having same issue as I was trying to create shutdown for my server so it is turned of during the night (I did configure my linux VM's to do the same 10 minutes before even in "root" cron job on ESXi host)

Reply
0 Kudos