LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 10-26-2011, 06:22 AM   #1
tg3793
Member
 
Registered: Jul 2009
Location: Philippines
Distribution: Linux Mint 13 (Mate Edition)
Posts: 50

Rep: Reputation: 12
Pass Shell Script to Background Process


Good morning. I'm trying to execute a shell script at the CLI and have it continue to run in the background even after the terminal closes.

This is what I've tried so far. Thanks;

Code:
sudo ./.ganttProj/ganttproject.sh && exit
sudo ./.ganttProj/ganttproject.sh &
bash -lic "sudo ./.ganttProj/ganttproject.sh & exit"
All three of them seem to get stuck at the end with GantProject doing a "Writing log to /home/scribe/.ganttproject.log"

The last one however has the advantage of GanttProject continuing to run after I manually do a ^C

Thanks for any help.
 
Old 10-26-2011, 08:18 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,122

Rep: Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819
Take a look at nohup.

In your shell program, make sure that you've used absolute path names for all commands and files; might help, can't hurt. You do not need to use exit with a program running in background, when it finishes the process will die (so, yeah, make sure that the process will actually finish and exit by running it in foreground). Oh, and when you launch it don't use the "./.balh," use absolute path name (avoids trouble). Finally, it's not a terribly good idea to run stuff with sudo; you may want to look into why you are running with sudo and what you can do so that is not needed.

Hope this helps some.
 
Old 11-03-2011, 02:57 AM   #3
tg3793
Member
 
Registered: Jul 2009
Location: Philippines
Distribution: Linux Mint 13 (Mate Edition)
Posts: 50

Original Poster
Rep: Reputation: 12
Ok so here is a list of what I have tried so far and the results.

- - - - - - - - - - - - - - - - - - - - -

bash -lic "sudo ./.ganttProj/ganttproject.sh && exit"
Which works but leaves a CLI open; not passing the command in the background.

nohup bash -lic "sudo ./.ganttProj/ganttproject.sh"
popped open a CLI and then closed.

nohup sudo ./.ganttProj/ganttproject.sh
popped open a CLI and then closed.

nohup ./.ganttProj/ganttproject.sh
popped open a CLI and then closed.

bash -lic "sudo ./.ganttProj/ganttproject.sh &"
popped open a CLI and then closed.
 
Old 11-03-2011, 07:09 AM   #4
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,122

Rep: Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819
Why don't you try this:
Code:
chmod 755 ./.ganttProj/ganttproject.sh
nohup ${HOME}/.ganttProj/ganttproject.sh 2>&1 > /tmp/ganttproject.log &
OR
cd .ganttProj
nohup ./ganttproject.sh 2>&1 > /tmp/ganttproject.log &
That will launch your shell program in background, detach it from the terminal (so the terminal window can just sit there and you can type commands or whatever) and execute until it finishes.

You do not need to launch it with bash -cli blah to do this; the first line of your shell program should be
Code:
#!/bin/bash
You also do not need to (and should avoid doing) sudo to run this unless there is something you cannot read from or write to logged in as "you." If you cannot access something logged in as you, fix that or change the owner of the shell program to root and turn on the so-called su-bit so it'll run as root; i.e.,
Code:
su -
chmod 4755 ./.ganttProj/ganttproject.sh
^D OR exit
nohup ${HOME}/.ganttProj/ganttproject.sh 2>&1 > /tmp/ganttproject.log &
Monitor what's going on -- if your shell program produces messages -- with
Code:
tail -f /tmp/ganttproject.log
Hope this helps some.

Last edited by tronayne; 11-03-2011 at 09:48 AM. Reason: Forgot a dot
 
Old 11-03-2011, 12:42 PM   #5
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,122

Rep: Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819
OK, I got to wondering what the heck you're trying to do so I went and downloaded and installed ganttproject-2.0.10.zip. It works just fine simply by opening a console window and entering
Code:
cd .ganttproject
sh ganttproject.sh
And, looking over your posts it looks like you may not have Java installed: You should be able to execute
Code:
whereis java
and see where java resides on your system (if it ain't there it ain't gonna work).

You could look in the log file that's created every time your run the program: ./.ganttproject.log; might give you a hint or two.

Frankly, there is no reason on this earth to execute that program in background, with sudo or any other variant of those -- it opens a screen, you can open the example provided with the download (HouseBuildingSample.gan).

Hope this helps some.
 
Old 11-04-2011, 05:57 AM   #6
tg3793
Member
 
Registered: Jul 2009
Location: Philippines
Distribution: Linux Mint 13 (Mate Edition)
Posts: 50

Original Poster
Rep: Reputation: 12
Quote:
Originally Posted by tronayne View Post
Why don't you try this:
Code:
chmod 755 ./.ganttProj/ganttproject.sh
nohup ${HOME}/.ganttProj/ganttproject.sh 2>&1 > /tmp/ganttproject.log &
OR
cd .ganttProj
nohup ./ganttproject.sh 2>&1 > /tmp/ganttproject.log &
That will launch your shell program in background, detach it from the terminal (so the terminal window can just sit there and you can type commands or whatever) and execute until it finishes.
tronayne; thanks so much for the feedback. I already checked the permissions in the GUI through nautilus and my username had read/write and execute access already. However just in case something was botched in the GUI I did the "chmod 755 ./.ganttProj/ganttproject.sh" as you had suggested.

Next here is the result of the next line I copied and pasted:
Code:
nohup ~/.ganttProj/ganttproject.sh 2>&1 > /tmp/ganttproject.log &
[1] 26469
scribe@scribe-desktop:~$ nohup: ignoring input and redirecting stderr to stdout
ganttproject.sh never seemed to run; or at least I never got the GUI that I had previously been getting.

I'll go through your other recommendations in a few moments.
 
Old 11-04-2011, 06:12 AM   #7
tg3793
Member
 
Registered: Jul 2009
Location: Philippines
Distribution: Linux Mint 13 (Mate Edition)
Posts: 50

Original Poster
Rep: Reputation: 12
Quote:
Originally Posted by tronayne View Post
And, looking over your posts it looks like you may not have Java installed: You should be able to execute
Code:
whereis java
and see where java resides on your system (if it ain't there it ain't gonna work).

Frankly, there is no reason on this earth to execute that program in background, with sudo or any other variant of those -- it opens a screen, you can open the example provided with the download (HouseBuildingSample.gan).

Hope this helps some.
Ok here is my java:

Code:
java: /usr/bin/java /etc/java /usr/share/java /usr/share/man/man1/java.1.gz
The reason for wanting to push the program into the background is because I'm trying to create a shortcut to it in the Gnome applications dropdown. And if I'm going to run it from there then why would I want to have both the GUI 'and' an extra terminal open :-)

I'll be happy to follow any instructions you give me. Thanks for your help.

Last edited by tg3793; 11-04-2011 at 06:14 AM.
 
Old 11-04-2011, 07:53 AM   #8
Andrew Benton
Senior Member
 
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073

Rep: Reputation: 64
If you want to run a program in the background after you've closed the terminal try using setsid. Eg:
Code:
sudo setsid ./.ganttProj/ganttproject.sh && exit
 
Old 11-04-2011, 01:53 PM   #9
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,122

Rep: Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819
One of the instructions at http://www.ganttproject.biz/download is:
Code:
Make sure that Sun's Java Runtime is installed on your Linux box and that you can run java from the command line. Unzip the file in your home directory ($HOME) and run $HOME/ganttproject-2.0.10/ganttproject.sh script.
Please note that GanttProject will not run with gij/gcj Java Runtime which comes by default with some Linux distributions. You do need either Sun's JRE or OpenJDK.
Note the bold face above: Do you in fact have Sun's Java Runtime (JRE) installed?

One way to tell is
Code:
java -showversion
Which should show you something similar to this:
Code:
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)
<and lot's more stuff on down from there; note yours may not be 64-bit>
Hope this helps some.
 
1 members found this post helpful.
  


Reply

Tags
bash, cli, command line


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 pass MySQL user/pass securely in shell script? digity Linux - Newbie 5 01-07-2010 06:48 AM
pass variable from one shell script into another shell script xskycamefalling Programming 9 10-03-2009 02:45 AM
Shell script help: How to pass a directory path to the script? dv502 Programming 13 09-10-2008 04:07 AM
How to stop a process running in background (on a shell script) Azk00 Linux - Newbie 3 02-01-2008 05:24 AM
shell script switching it self into background process knockout_artist Linux - Software 3 11-24-2007 12:33 PM


All times are GMT -5. The time now is 11:51 PM.

Main Menu
Advertisement
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