LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 09-17-2006, 01:09 PM   #1
Maverick1182
Member
 
Registered: Aug 2004
Location: London
Distribution: Gentoo
Posts: 277

Rep: Reputation: 30
running java program at startup in background


Hi there, i know how to run modules and bash scripts at startup but can anyone tell me how i can run a java script in the background? i need to be able to run the Mr postman java script without opening a console up everytime and running the following command:

java -jar /usr/local/MrPostman/MrPostman-20060106.jar

I've noticed that it outputs stuff in the window which it is being run, will this be a problem if it is run in the background? Most help guides say the command needs to return to the command prompt. On running this command it does not let you go back to the prompt until you strike ctrl+C


Do I simply need to add an & to the end of this command and then copy it to /etc/conf.d/local.start(is this still correct for gentoo) ?

Last edited by Maverick1182; 09-17-2006 at 01:21 PM.
 
Old 09-19-2006, 11:25 AM   #2
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
Yep, you should be able to throw a & on the end and add it to the startup script. I'd recommend piping the output to a log though (just in case). Also, you might need to source your bash profile first to ensure that JAVA_HOME is set properly. I'd try something like:
Code:
source ~/.bashrc
java -jar /bla/bla/bla.jar &> logfile.txt &
 
Old 09-19-2006, 02:04 PM   #3
Maverick1182
Member
 
Registered: Aug 2004
Location: London
Distribution: Gentoo
Posts: 277

Original Poster
Rep: Reputation: 30
K, will it append to the log every time it runs? or does it over right it? i creates a lot of output when i'm accessing my mails and i dont want the file getting larger and larger.... alough i could probably run a command at shutdown to delete the file. wow. linuxs kick windows bum! lol thanks again

Last edited by Maverick1182; 09-19-2006 at 02:06 PM.
 
Old 09-19-2006, 02:12 PM   #4
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
Yep, using a single > will cause a new log file to be created each time. You can use >> to append to an existing file. Heck you could throw it into logrotate and let it be gzipped and cycled like all the /var/log/ stuff. Or, don't even log it, the choice is yours (which is part of why Linux kicks Windows bum, as you say )
 
Old 09-19-2006, 06:09 PM   #5
Maverick1182
Member
 
Registered: Aug 2004
Location: London
Distribution: Gentoo
Posts: 277

Original Poster
Rep: Reputation: 30
i tried adding the following lines to the

source ~/.bashrc
java -jar /usr/local/MrPostman/MrPostman-20060106.jar & >> /home/mark/mailoutput.txt &

i gave no joy when it booted so i copied and pasted into a console as i figured it should do the same thing...

unfortunately it still outputs to the screen whilst creating the required file which has nothing in it

Am i not piping correctly? Should there be an & at the end of java line? any ideas? Thanks for your help so far though Vgui
 
  


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
Running a program at startup allomeen Linux - General 5 02-15-2006 06:36 PM
running a program in background of X using & Dachy Linux - General 1 09-13-2005 11:38 AM
running rsync from a background c program BassJunkie Programming 2 08-26-2005 05:38 AM
Running a program in the background - SSH ziggo0 Linux - Newbie 4 03-05-2005 01:30 PM
java program in background nephilim Programming 11 10-20-2003 06:49 AM


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