Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 11-23-2007, 10:55 PM   #1
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Rep: Reputation: 33
shell script switching it self into background process

Good Day,

I need a shell script which after performing its primary tasks switch it self into a background process for to min. and then exit.

mount /nfs/remote/parition
display message"so and so is mounted for you"
switch to background process giving command prompt.
it shows prompt to user

(in background)
wait for 4 mins.
kill few processes

Thank you.

Note:All this hassle because we only have one console(init 3).
Old 11-24-2007, 03:15 AM   #2
Registered: May 2001
Posts: 29,359
Blog Entries: 55

Rep: Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546
Originally Posted by knockout_artist View Post
Note:All this hassle because we only have one console(init 3).
How about using 'screen' instead, then?
Old 11-24-2007, 06:29 AM   #3
Senior Member
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Stretch/Sid, Linux Mint DE
Posts: 4,631

Rep: Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711
Well, backgrounding the script is easy. Just put an '&' at the end of the command line when you call the script.

Any messages of your script piped to stsout will show up on you console. Those piped to /dev/null won't.

Use sleep to suspend the script for the delay action.

After the script is finished waiting, it can exit.

A backgrounded script doesn't differ in anything from a fg running script except that it cannot receive kbd input. Writing to stderr still works, stdout I am not sure.

Old 11-24-2007, 11:33 AM   #4
Senior Member
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
And, within a script, you can start a child process and then disown it. Here's an example (written because the JSView Firefox extension assumes that any "executable" has an ".exe" extension, and this was easier than fixing the extension code.)
$ cat Scripts/kate.exe
kate $* &
disown -h
The code starts kate, disowns it after telling the child to ignore hangup, and then exits.


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
how do i get a shell script to run in the background? tjyorkshire Programming 4 07-06-2007 02:28 AM
kill the process invoked from a shell script, when the script is killed kskkumar Linux - Software 8 05-23-2007 11:29 AM
verify if the same shell script is executing in background hicham007 Programming 2 08-07-2005 05:40 AM
bash script to accept input ONLY until background process completes andrewstr Linux - Software 2 03-17-2004 12:02 PM
shell script switching user question compupurdy Linux - Newbie 1 11-22-2003 09:03 AM > Forums > Linux Forums > Linux - Software

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

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