LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 11-23-2007, 10:55 PM   #1
knockout_artist
Member
 
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.

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

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


Thank you.

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

Rep: Reputation: 2908Reputation: 2908Reputation: 2908Reputation: 2908Reputation: 2908Reputation: 2908Reputation: 2908Reputation: 2908Reputation: 2908Reputation: 2908Reputation: 2908
Quote:
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
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,171

Rep: Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506
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.

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

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
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.)
Code:
$ cat Scripts/kate.exe
#!/bin/bash
kate $* &
disown -h
The code starts kate, disowns it after telling the child to ignore hangup, and then exits.
 
  


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
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


All times are GMT -5. The time now is 10:51 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