Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a shutdown for a script.

Status
Not open for further replies.

nerbonne

Technical User
Dec 11, 2006
99
US
I have two questions about scripts:

1) How can I write a shutdown script for a script that runs automatically. For instance, I have a script that runs backups as soon as the computer boots, and then shuts down the computer when it is done. Periodically, I want the computer to stay up. I think the easiest way to do this would be to make the script check for the existance of a lock file before it shuts down, and if it exists, it just exits without shutting down. Can anyone give me a brief example of how to accomplish this?

2) Secondly, I have my backup script written, but it only works when I run it manually. When it is run on bootup, the commands where it logs into the other servers to run a job works, but the rsync command does not run. I'm not sure why this is? Like I said, everything works fine when I run it manually. Any ideas?

Thanks.
 
Regarding the first question...can you confirm when (and under) what circustances you want the machine to stay up or shutdown.

The reason the backup script isnt working maybe down to the system variables assigned to the shell you are trying to run it in. Have you put the full path of the rsync binary into the script ?
Also try running your script via running a trace (for debugging) ... try #sh -x [yourscript]

Felix -
 
Well, under normal operations the computer will boot itself every night. Upon bootup, the backup script should run, and then at the end of the script the last command is to shutdown. Some days I want to work on the server, so I need to be able to turn off the shutdown.

I will check on the paths and also use the trace command that you provided.
 
I believe the best way to acheive this would be to ( like you say ) tell the script to look for a certain lock file and give it a time period in which from the machine booting up to when you will be working on it... ie....

script starts,
will look for a lock file for the next couple of hours,
if lock file not found then it will shutdown.

 
I'm still rather confused about the circumstances when this (ie startup, backup, shutdown) would be a desirable thing to do.

I want to be good, is that not enough?
 
I was wondering why the boot process at all? There is actually less wear and tear just letting it run. Then all scheduled events can be handled through cron. If security issues are what are holding you back, you can limit access to only ports you will need to admin the unit and allow acces from just one ip address. Your script may not have permission to access or run some of its commands.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top