LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-29-2007, 06:59 PM   #1
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Rep: Reputation: 39
Question Trying to work out how to run a script with a start command or something similar


OK this could be confussing but i'll do my best to explain it. What i'm looking to do which i dont really have any idea how to currently is something like running a script from one file which runs the script in another file depending on a code name as it were.

Like when you do something like "network start" or "service smb stop". "start" and "stop" obviously being code words within the specific smb or network file within if i remeber /etc/rc.d/*

So i'm looking to know how i can have one file that has a script in it and instead of having a variable file sourced with the commands there and then just source the file and use the command, i'd like to instead run another file somehow and it then only runs the script according the the corrisponding code name like a case script, its so several different scripts can all point to and run from one file where as at the moment i have lots of different files so everytime i change a bit in one file i have to change the same thing in all the other files, so to run specific parts with the use of a code name type thing or something would be very useful

i hope that makes sense, probably not

Thanks for anyhelp
 
Old 05-30-2007, 03:31 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
Well, you could copy one of those scripts as a start.
The main script needs to have a search path of somekind to know where to look to find the 2nd script ie a 'service' script would need to know where to find the 'smb' script and fwd the remaining params to it.
 
Old 05-30-2007, 06:27 AM   #3
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
yes that sounds to be exactly along the write lines, how do i do the search path your sugesting? OR how is it searched when using the standard linux commands like "service start | stop | restart | etc OR /etc/rc.d/init.d/servicename start | stop | etc" There must be a way that the distro works out the second script i can guess it somehow uses the "servicename" as the file name as they are the same, and then just run the selected code script, any ideas how to create the search path,

Thanks for the reply most helpful, i'm going to search into search paths now also, i didn't have a clue where to start looking at least yu have given me an idea thanks

Last edited by helptonewbie; 05-30-2007 at 06:32 AM.
 
Old 05-30-2007, 06:51 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
The items after the command are arguments. I think you are asking about the case command.

read through the
info bashref
manual.

Also enter "help case"

Last edited by jschiwal; 05-30-2007 at 07:17 AM.
 
Old 05-30-2007, 07:09 AM   #5
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
Thanks for that, but i've got it all working now just this second, case command already i've completed the task chrism said which was to just re-write one of the other files which works fine, currently just echo's start or stop or status etc depending on what i have as my codename command.

all i want now is to be able to run it, i can do that using "service scriptname start | stop | status"

I've also re-written the "path" parameter so i had it pointing directly at my script and that works fine when i typed in "scriptname start | stop | status". Only problem is, is there a way to just add to the "PATH" path search parameter, variable that you just add in my new PATH or do you have to re-write the whole variable, it would be better if there is a way to just make it add my extra path to the end if possible?
thanks for your reply anyway

Last edited by helptonewbie; 05-30-2007 at 07:12 AM.
 
Old 05-30-2007, 07:56 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
In your .bash_profile (hidden file in home dir) should be something like this:

PATH=$PATH:$HOME/bin

Just add your extra to the end, precede by a colon ( ':' ) as per this.
You'll need to logout and back in to make it take effect.
Basically, each time you open a new terminal/logon, it reads this file (and any called therefrom eg .bashrc)
 
Old 05-31-2007, 05:27 PM   #7
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
thanks there, that is useful info
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
start xterm and run command? P-P Linux - Software 3 01-19-2007 07:35 PM
Run Shell COmmand on start-up evilmonkey Linux - Software 3 05-21-2006 06:24 PM
How to run a command automatically on start up TKD Suse/Novell 6 11-03-2005 05:41 AM
New to XFCE4 how do I run a command at its start. Royle Debian 1 02-19-2005 01:11 PM
start up script run once ?? johnyy Linux - Software 1 12-28-2003 02:59 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration