-   Programming (
-   -   Trying to work out how to run a script with a start command or something similar (

helptonewbie 05-29-2007 05:59 PM

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

chrism01 05-30-2007 02:31 AM

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.

helptonewbie 05-30-2007 05:27 AM

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

jschiwal 05-30-2007 05:51 AM

The items after the command are arguments. I think you are asking about the case command.

read through the
info bashref

Also enter "help case"

helptonewbie 05-30-2007 06:09 AM

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

chrism01 05-30-2007 06:56 AM

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


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)

helptonewbie 05-31-2007 04:27 PM

thanks there, that is useful info :)

All times are GMT -5. The time now is 10:45 AM.