LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 07-27-2004, 06:05 PM   #1
NetAX
Member
 
Registered: Mar 2004
Location: Boston, MA
Distribution: SuSE Linux Open/Enterprise, Red Hat, Ubuntu
Posts: 147

Rep: Reputation: 17
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.
 
Old 07-27-2004, 06:30 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,341

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
"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
 
Old 07-27-2004, 11:10 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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.
 
Old 07-29-2004, 03:09 PM   #4
NetAX
Member
 
Registered: Mar 2004
Location: Boston, MA
Distribution: SuSE Linux Open/Enterprise, Red Hat, Ubuntu
Posts: 147

Original Poster
Rep: Reputation: 17
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?
 
Old 07-29-2004, 03:30 PM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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
 
Old 07-29-2004, 03:45 PM   #6
NetAX
Member
 
Registered: Mar 2004
Location: Boston, MA
Distribution: SuSE Linux Open/Enterprise, Red Hat, Ubuntu
Posts: 147

Original Poster
Rep: Reputation: 17
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.
 
Old 07-29-2004, 03:47 PM   #7
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,341

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
"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
 
Old 07-29-2004, 03:52 PM   #8
NetAX
Member
 
Registered: Mar 2004
Location: Boston, MA
Distribution: SuSE Linux Open/Enterprise, Red Hat, Ubuntu
Posts: 147

Original Poster
Rep: Reputation: 17
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux boot up process Vs. Windows boot up process darkskull Linux - Software 7 12-30-2006 04:21 PM
Process monitor script? sub_moa Programming 2 11-03-2005 04:08 AM
add a process to boot? alphamike Linux - Newbie 3 09-06-2005 12:20 PM
Process killing script owix Linux - General 2 07-19-2005 11:08 AM
how do I add script to set default gateway on boot for eth1 abg Linux - Networking 3 10-01-2003 05:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration