How to add script to boot process
Hi, i'm having trouble with adding a script that i have written to the initial startup of the OS. One method that i tried ended up with the system hanging after a certain processes started. Luckly i fixed it by booting in runlevel 1 and removing what i did.
This is a small basic script to shutdown the system after a period of time.(To save electricity:)) temph=`date | cut -c12-13` tempm=`date | cut -c15-16` while [ $temph -eq 19 ] do date if [ $tempm -gt 1 -a $tempm -le 11 ] then init 0 fi done I want to be able to add this to the boot process so the loop will start automatically. I have heard of symbolic links but i dont know how that works. I hope somebody can help me.:) |
"This is a small basic script to shutdown the system after a period of time."
Rather than starting your script when you boot I suggest that you use cron to start a shutdown script at a fixed time interval after boot. See: man cron man crontab "I have heard of symbolic links but i dont know how that works. " A symbolic link is an alias for a file or directory. For example if I wanted /usr/local/Compiler to be an alias for gcc I would use the ln command to set up a symbolic link: ln -s /usr/bin/gcc /usr/local/Compiler See: man ln ___________________________________ Be prepared. Create a LifeBoat CD. http://users.rcn.com/srstites/LifeBo...home.page.html Steve Stites |
jailbait is right... I would set up a cron job for automatic shutdown.
If you're intent on getting the script to work (as a learning excerise or whatnot), there is a problem with it. You assign values to tempm and temph initially, and use them to control when to leave your while-loop and when to execute "init 0". The problem is, their values never change. To have them update, you need to change your script to something like: Code:
temph=`date | cut -c12-13` |
Hi thanks for the replies. I was able to get the cronjob to work to some extent, however, whenever it executed the shutdown script it mailed me saying that 'init command was not found.'
I have only one line in my script now and it is 'init 0'. This command works fine with the bash executing it, but it doesn't work for the cron job. this is my crontab file: SIAServer:~ # crontab -l MAILTO=root 30 16 * * * bash $HOME/bin/daily.job this is my script file: init 0 Maybe i'm doing something wrong? |
No, but this is a normal "gotcha". Your cron environment is not identical to your normal/user environment. Specifically, your PATH environment is not the same. If you add the full path to init, you'll be fine. It should be /sbin/init
|
Thanks a lot Dark_Helmet!! It worked! Got plenty of jobs to add now.
I wonder why /sbin has to be included to make 'init' work while the commands in /bin dont even need the directory to be executed. |
"this is my script file:
init 0" Depending on what your applications are doing you might want to use the shutdown command. With the shutdown command you can send the running applications a "save yourself" signal and then allow a few seconds for them to close files, etc. before you shutdown. So to give everything 10 seconds grace you would use: /sbin/shutdown -t 10 -h now See: man shutdown ___________________________________ Be prepared. Create a LifeBoat CD. http://users.rcn.com/srstites/LifeBo...home.page.html Steve Stites |
Thanks jailbait for your reply. Im not running any heavy applications right now, but i think i will use that command line you wrote for my database server when i get that up.
|
All times are GMT -5. The time now is 05:15 PM. |