views:

288

answers:

6

I need to have a script execute (bash or perl or php, any will do) another command and then exit, while the other command still runs and exits on its own. I could schedule via at command, but was curious if there was a easier way.

+6  A: 
#!/bin/sh

your_cmd &

echo "started your_cmd, now exiting!"

Similar constructs exists for perl and php, but in sh/bash its very easy to run another command in the background and proceed.

edit

A very good source for generic process manipulation are all the start scripts under /etc/init.d. They do all sorts of neat tricks such as keep track of pids, executing basic start/stop/restart commands etc.

Ernelli
+2  A: 
mobrule
How did you get a four horned unicorn, with all four horns on its head?
Tim Post
It's one horn, but it's standing in front of a rainbow.
mobrule
+3  A: 

I'm not entirely sure if this is what you are looking for, but you can background a process executed in a shell by appending the ampersand (&) symbol as the last character of the command.

So if you have script, a.sh

and a.sh needs to spawn a seperate process, like say execute the script b.sh, you'd:

b.sh &
Tibrim
+6  A: 

To run a command in the background, you can append an '&' to the command.

If you need the program to last past your login session, you can use nohup.

See this similar stackoverflow discussion: how to run a command in the background ...

Jay Elston
+1  A: 

So long as you mentioned Perl:

fork || exec "ls";

...where "ls" is anything at all. Repeat for as many commands as you need to fire off.

cikkle
A: 

The usual way to run a command and have it keep running when you log out is to use nohup(1). nohup prevents the given command from receiving the HUP signal when the shell exits. You also need to run in the background with the ampersand (&) command suffix.

$ nohup some_command arg1 arg2 &
camh