LinuxQuestions.org
Help answer threads with 0 replies.
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 02-03-2006, 11:27 AM   #1
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676
Blog Entries: 7

Rep: Reputation: 32
execute shell script found in /root/ on startup


Hi
Ive got a debian box without a desktop environment nor a monitor...I access it through ssh...I use it as a router..Ive created a bash script that contains all the rules and IP addresses etc...I want this script to be executed everytime my router starts..the script is found in /root/ ..and it must remain there..for several reasons...

The solution I got was as follows
create a file in /etc/init.d/test
then update-rc.d test defaults 99 "I know about 99 S K and defaults"
this should allow the test file to be executed at startup..but what about a script found in /root/ ? Does update-rc.d allow me to call files not found in /init.d/ or should I just enter an entry in lets say the mentioned test file that calls the file found in root...when it is called at startup ?

Last edited by ALInux; 02-03-2006 at 12:45 PM.
 
Old 02-03-2006, 02:33 PM   #2
accessrichard
Member
 
Registered: Apr 2005
Distribution: Fedora Core (latest version)
Posts: 156

Rep: Reputation: 30
I am confused about your questions, I usually put scripts that I want to run at startup in rc.local. I am pretty sure that by default these scripts run as root and therefore can access scipts owned by root in any directory. If not than change the permissions of your /etc/init.d/test file to run as "set uid".

I hope I understood your questions right and that I was of help.

Depending on what you are doing, it is also possible to add your script to the ethernet configuration scripts so that when your router connects to the internet your scripts are run right away. For instance on my laptop, I use wpa encryption, and want the wpa_supplicant to run before I connect to the internet, so I edit the
/etc/sysconfig/network-scripts/ifup-wireless
script in order to run a few commands or call another script before or right after the wireless card connects to the AP.

P.S. I like the design of your web page, it looks really nice!

Last edited by accessrichard; 02-03-2006 at 02:41 PM.
 
Old 02-03-2006, 02:59 PM   #3
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676

Original Poster
Blog Entries: 7

Rep: Reputation: 32
Thx..for you help...Ive got it figured out..the prob was that debian does not have a rc.local file and furthermore it differs in some particular aspects from other distros but now its done...thx again
 
Old 02-06-2006, 11:37 AM   #4
cf050
LQ Newbie
 
Registered: May 2004
Location: Rostock, Germany
Distribution: Ubuntu 6.06 on amd64
Posts: 25

Rep: Reputation: 15
Why don't you post how you actually did it??????
 
Old 02-06-2006, 12:15 PM   #5
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
AFAIK, there is nothing special about the /etc/init.d directory. That's just where startup scripts are stored by convention, not by mandate. I could be mistaken on this ... I've never actually tried placing an init script outside of /etc/init.d It would be simple enough to run a quick test if you wanted to.

But assuming I'm correct about scripts outside of /etc/init.d being allowable:

If you want /root/myscript to run when you hit runlevel 2, 3, and 4 for example, you should be able to do something like this:
Code:
ln -s /root/myscript /etc/rc2.d/S99local
ln -s /root/myscript /etc/rc3.d/S99local
ln -s /root/myscript /etc/rc4.d/S99local
Your /root/myscript file should understand standard startup script options, like "start", "stop", "restart", etc. I suppose if you're only creating an Sxxx link then all it's needs to understand is "start". If you also create a Kxxx script, then it needs to understand "stop".

I find those "update-rc.d" type of wrapper programs to be more trouble than just doing things manually.
 
Old 02-07-2006, 01:12 PM   #6
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676

Original Poster
Blog Entries: 7

Rep: Reputation: 32
To CF50... you create your script and save it in /etc/init.d/ and then you execute update-rc.d yourfilename 99 defaults ...this will add your file to the startup of your debian system..99 means that it will be the last file to be executed and defaults means that it will be added to all run-levels...to add it only to specific run levels...execute update-rc.d filename 99 s 2 3 5. "with the period at the end" and of course you can "man update-rc.d".

The issue I had was that my startup file had to be in a user directory so that a user can edit it from there "for alot of diff reasons" so I created a file in /etc/init.d/ and just told it to execute /home/directory of user/myscript.sh
That way every time the system boots it calls my file, in that file I added my firewall configuration and the progs I want to start each time. It is easier to edit the whole configuration of the system that way

Edit: Actually haertig...Iam doing it that way now.. it is always better to be closer to the actual way things work

Last edited by ALInux; 02-07-2006 at 01:17 PM.
 
Old 02-07-2006, 01:22 PM   #7
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by ALInux
The issue I had was that my startup file had to be in a user directory so that a user can edit it from there "for alot of diff reasons"...
Just realize that this user, actually ANY user who can write this startup file, owns your system. They can do anything they want ... as userid root. This cannot be considered secure in any way, shape or form. However, everybody's situation is different and maybe your setup does not require much security (possibly YOU are the only user, etc.)

[edit]
See another thread related to this topic here:
http://www.linuxquestions.org/questi...d.php?t=411781
[/edit]

Last edited by haertig; 02-07-2006 at 01:24 PM.
 
Old 02-07-2006, 01:25 PM   #8
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676

Original Poster
Blog Entries: 7

Rep: Reputation: 32
Only user here...as you said...but thx for pointing it out..since it could create a security issue for other folks....
 
  


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
Howto launch script at startup sendas4 Linux - Newbie 2 03-10-2005 10:51 AM
auto execute shell script on startup slackwbas Slackware 9 02-27-2005 10:26 AM
custom-made redhat distro srns Red Hat 1 12-15-2004 08:15 PM
Custom-Made Installation DVD from 4-CD ISO Set? jdanniel Linux - Newbie 1 08-07-2004 01:06 PM
IceWM doesn't execute my startup script martinpi Linux - Software 1 05-28-2004 02:24 AM

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

All times are GMT -5. The time now is 05:53 AM.

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