spitzmann2
Contributor
Contributor

any shell script I create inside ESXi is deleted !

Jump to solution

Why any .sh file I create inside ESXi is deleted ?

I'm trying to start some scripts from Cron.

I check this tutorial but I loose my .sh files inside /opt or /etc anytime I make a reboot ! Is Vmware trying to break us ?

Tags (4)
0 Kudos
1 Solution

Accepted Solutions
Dave_Mishchenko
Immortal
Immortal

Are you making the change to rc.local? That file gets backed up into state.tgz (or local.tgz) which ensures that the change survives a reboot. When you change that file you can manually backup the host with /sbin/auto-backup.sh. When you extract state.tgz you should then see your modified state.tgz file.




Dave

VMware Communities User Moderator

Now available - vSphere Quick Start Guide

Do you have a system or PCI card working with VMDirectPath? Submit your specs to the Unofficial VMDirectPath HCL.

View solution in original post

0 Kudos
19 Replies
spitzmann2
Contributor
Contributor

this is the tutorial I follow. No success.

http://www.jules.fm/Logbook/files/add_cron_job_vmware.html

0 Kudos
Dave_Mishchenko
Immortal
Immortal

Are you making the change to rc.local? That file gets backed up into state.tgz (or local.tgz) which ensures that the change survives a reboot. When you change that file you can manually backup the host with /sbin/auto-backup.sh. When you extract state.tgz you should then see your modified state.tgz file.




Dave

VMware Communities User Moderator

Now available - vSphere Quick Start Guide

Do you have a system or PCI card working with VMDirectPath? Submit your specs to the Unofficial VMDirectPath HCL.

View solution in original post

0 Kudos
Meelhuysen
Contributor
Contributor

Hi Dave,

I have the same problem here.

I've created a shutdownvms.sh and added it to the bin folder on the esx4i server.

The script works but after a reboot of the server the script is gone.

I've tried the backup command you posted but no luck.

Is there something that i'm missing here?

Looking forward to your answer.

Thanks

0 Kudos
Dave_Mishchenko
Immortal
Immortal

Welcome to the VMware Communities forums.  You can either bundle the file in an oem.tgz file - http://www.vm-help.com/esx40i/customize_oem_tgz.php or if the file is within /etc you can enable the sticky bit on the file and it will be backed up into state.tgz (or local.tgz). You can use the command chmod +t <filename> for that.

0 Kudos
Meelhuysen
Contributor
Contributor

Hi Dave,

If i put the file in the etc and ad the sticky bit reboot the file is still gone.

Or is there someting els i have to do to get it working?

Thanks

0 Kudos
Dave_Mishchenko
Immortal
Immortal

When a file is in /etc and has the sticky bit enabled,  the auto backup routine will add it to state.tgz.  That runs at 1 minute past every hour or during a clean shutdown / restart.

You can manually start the backup process with the console command   /sbin/auto-backup.sh 0 /bootbank/

After you run that you can copy oem.tgz to /tmp, extract it and verify if your file has made it into the config backup.

0 Kudos
Meelhuysen
Contributor
Contributor

Hi Dave,

If i runt the back up command and lookinto the  oem.tgz it is empty.

It does not back-up the file that i put in there. very strange.

I'm using ESXi 4.1.0 build-348481

0 Kudos
Dave_Mishchenko
Immortal
Immortal

You want to check state.tgz and not oem.tgz.

0 Kudos
Meelhuysen
Contributor
Contributor

Hi Dave,

I've completely reinstaled the esxi server.

Put the .sh file in the etc folder and added the sticky byte.

Run the 2 back-up commands that you gave me.

Looked into the state.tgz in the altbootbank folder.

Opened it and the local.tgz is in there. Open that and the etc folder is in there.

But my file that i've created is not in the folder.

Reboot the machine and the file is gone again.

Is there still sometng that i'm not doing correct?

.

0 Kudos
Dave_Mishchenko
Immortal
Immortal

You'll want to check the file in /bootbank.

0 Kudos
Meelhuysen
Contributor
Contributor

Hi Dave,

Also looked in the /bootbank folder but no luck

0 Kudos
Dave_Mishchenko
Immortal
Immortal

When you put the file in /etc and enable the sticky bit you can run ls -l  to verify the setting.  The file should have a T in the file attributes.  Something like this -


-rw-r--r-T    1 root     root                442 Apr  8 06:48 inetd.conf

0 Kudos
Meelhuysen
Contributor
Contributor

Hi Dave,

I've checked al the things but no luck.

I've attached the logging of my steps.

The file named shutdownvms.sh is the file that is giving the problem.

If you look at the output of the back-up commands the file is not back-upt.

Should it normaly stand there in the list?

0 Kudos
Walfordr
Expert
Expert

Meelhuysen wrote:

Hi Dave,

I've checked al the things but no luck.

I've attached the logging of my steps.

The file named shutdownvms.sh is the file that is giving the problem.

If you look at the output of the back-up commands the file is not back-upt.

Should it normaly stand there in the list?

The sticky bit does not seem to be working in ESXi 4.1 u1. - tried for a while in my lab.

The only way I have gotten this to work is by modifying the backup.sh script that is in /sbin.  The custom shell script remained, but then backup.sh is replaced so you would have to modify it again.

line 368 I added item in bold.  filestosave=$(find etc -follow -type f -name ".#*" -o -name "*.sh" 2> /dev/null | \

I would suggest that you create a folder in your [local] datastore and place the scripts there.  Then point to the datastore when calling them.  If you are using the datastore browser to upload the scripts make sure that you chmod the files after.

calling the script would be...

/vmfs/volumes/<datastore friendly name>datastore1/scripts/backup.sh

Regards,

Robert

Robert -- BSIT, VCP3/VCP4, A+, MCP (Wow I haven't updated my profile since 4.1 days) -- Please consider awarding points for "helpful" and/or "correct" answers.
0 Kudos
Dave_Mishchenko
Immortal
Immortal

I took a look at the backup script and it's looking for  hidden file corresponding to the actual filename that starts with .#.   So if I create a file called test1 I need to have another called .#test1 in the same folder.  If you run ls -a in /etc you'll see what I mean.   I don't think you can manually create the files, so editing the backup script should get the file into the backup file. 

Your change to the backup script won't persist, but the file will be in the configuration backup and the corresponding .# file should be created the next time you reboot.

0 Kudos
Meelhuysen
Contributor
Contributor

Hi Dave And Robert,

Thanks for your help.

The tip of Robert with editing the backup.sh file did the trick.

After a reboot the file is still in the etc folder.

But after the next reboot it is gone again.

The .# file is not created in the folder and that is why it is not backuped again.

Dave do you have any segestions about the .# file how to create it?

0 Kudos
Walfordr
Expert
Expert

Did you test saving the script in a datastore and use chmod to give read and execute rights like I suggested?

I think that is the best solution for you. You will not have to worry about modifying any other system files.

The .# files is probably being created by a binary running in the bg or hard coded in the kernel. I looked but could not find anything.

Good luck.

Robert

Robert -- BSIT, VCP3/VCP4, A+, MCP (Wow I haven't updated my profile since 4.1 days) -- Please consider awarding points for "helpful" and/or "correct" answers.
0 Kudos
Meelhuysen
Contributor
Contributor

Hey Robert,

I solved the problem.

Placed my script in the datastore.

Edited the rights on the file.

Now i'm able to execute the file from the datastore.

Robert&Dave thanks for the help!!!

0 Kudos
omaganarak
Contributor
Contributor

Hey. Please You Can help me.

        I'm still problem for Esxi 4.0 / 5.0 Because i need to Make Migration script for Check for Server or host .

Ex. It the Server 1 have the problem and shutdown so server 2 can start by self auto.

note : Please help me pls.

Thank so much

s.popromsri@outlook.com

Sak

0 Kudos