Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: SuSE Linux Open/Enterprise, Red Hat, Ubuntu
Posts: 147
Rep:
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)
"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:
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`
tempm=`date | cut -c15-16`
while [ $temph -eq 19 ]
do
temph=`date | cut -c12-13`
tempm=`date | cut -c15-16`
if [ $tempm -gt 1 -a $tempm -le 11 ]
then
init 0
fi
sleep 60
done
exit 0
I added teh sleep because I doubt you want the system to fire off "date" commands as fast as it possibly can, and coupled with the fact none of your conditions change unless a minute has expired.
Distribution: SuSE Linux Open/Enterprise, Red Hat, Ubuntu
Posts: 147
Original Poster
Rep:
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
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
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:
Distribution: SuSE Linux Open/Enterprise, Red Hat, Ubuntu
Posts: 147
Original Poster
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.