LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 07-05-2007, 06:07 PM   #1
tjyorkshire
Member
 
Registered: Jun 2007
Location: UK
Distribution: openSUSE 10.2
Posts: 138

Rep: Reputation: 15
Question how do i get a shell script to run in the background?


ok, im new to linux , This may be the most easiest things to do, but how do i run a shell script in the background?

thanks in advance!
 
Old 07-05-2007, 06:39 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
Use the & character when you start it up:
Code:
/path/to/your/script &
 
Old 07-05-2007, 06:40 PM   #3
x_terminat_or_3
Member
 
Registered: Mar 2007
Location: Plymouth, UK
Distribution: Fedora Core, RHEL, Arch
Posts: 342

Rep: Reputation: 38
bash has built-in job control capabilities

You can put jobs in the foreground and background at will

To put a job in the background from the start, append an ampersand at the end of the command:

updatedb&

Bash replies with
[1] 27267

The number between the brackets is bash' job number, the number next to it is the process id

Armed with this number, you can now put the job in the foreground with the command

fg 1

This will bring the program to the foreground (provided it has not terminated), and attaches the stdin to the console.

To put this job back in the background, press Ctrl+d

Also, you may type the command

jobs

To get a list of all running jobs and their status:

[1]+ Running updatedb &

All this and more from the bash man page (man bash)
 
Old 07-05-2007, 07:11 PM   #4
tjyorkshire
Member
 
Registered: Jun 2007
Location: UK
Distribution: openSUSE 10.2
Posts: 138

Original Poster
Rep: Reputation: 15
Talking

Thanks for your replies!, now i can get my startup script to work properly!
 
Old 07-06-2007, 03:28 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,298

Rep: Reputation: 175Reputation: 175
you can also use nohup which will keep it going when you close the terminal

also you can use batch or at

they are interactive though I usually do like this:

ls script | batch
or
echo script | at now + 10 minutes

the output is mailed to you on completion
 
  


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 to run a shell script in the perl script sharad Linux - General 1 05-24-2006 04:23 AM
verify if the same shell script is executing in background hicham007 Programming 2 08-07-2005 06:40 AM
How to run SHELL script pito Linux - Newbie 4 12-17-2004 04:05 AM
Shell script to run pl/sql script. colly Linux - General 1 09-09-2004 07:49 AM
How to run a bash command in the background from perl script professorfrink Programming 3 11-13-2003 04:02 PM


All times are GMT -5. The time now is 04:57 PM.

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