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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
10-23-2006, 06:49 PM
|
#1
|
|
Member
Registered: May 2006
Location: Cincinnati, Ohio
Distribution: Ubuntu
Posts: 256
Rep:
|
Easiest CRON Question in the World - RESOLVED
If I wanted to create a CRON job to run a program once, and ONLY once, at 21:00 EST today, and leave the program open until it is closed manually, how would I do it?
Last edited by RAdams; 12-15-2006 at 11:58 PM.
|
|
|
|
10-23-2006, 08:09 PM
|
#2
|
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Debian, FreeBSD, Ubuntu (desktop)
Posts: 3,859
Rep: 
|
Easy: use the at program. (Not cron.)
Quote:
|
... and leave the program open until it is closed manually, how would I do it?
|
I don't follow. What is the program?
|
|
|
|
10-24-2006, 03:11 AM
|
#3
|
|
Member
Registered: May 2006
Location: Cincinnati, Ohio
Distribution: Ubuntu
Posts: 256
Original Poster
Rep:
|
Quote:
|
Originally Posted by anomie
Easy: use the at program. (Not cron.)
I don't follow. What is the program?
|
Okay, here's the deal: it's a linux webserver. I have shell access, and would like to set up a script that runs the Ventrilo voice server. This program runs in terminal, and stays open until you quit it. I don't want this program to stop, and really ideally I'd like to somehow be able to interact with it... that makes it more complex, I realize.
|
|
|
|
10-24-2006, 05:34 AM
|
#4
|
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
Please define "interact". Does the program have a separate (GUI) window, started from a terminal? Or do you have to give input (ie type in words) in the terminal window?
In the first case, running the command that brings up the window in the background might help. In the second case, it won't help, though.
|
|
|
|
10-24-2006, 07:06 AM
|
#5
|
|
LQ Newbie
Registered: Oct 2006
Posts: 16
Rep:
|
Quote:
|
Originally Posted by RAdams
If I wanted to create a CRON job to run a program once, and ONLY once, at 21:00 EST today, and leave the program open until it is closed manually, how would I do it?
|
Why cron? cron is designed for periodically schedule processing.
In your case I'd use 'at' command.
--
Vladimir
unix-news.blogspot.com
|
|
|
|
10-25-2006, 01:54 AM
|
#6
|
|
Member
Registered: May 2006
Location: Cincinnati, Ohio
Distribution: Ubuntu
Posts: 256
Original Poster
Rep:
|
Ok, it's established "at" is what I need. Regarding the interaction, it runs via terminal. It isn't a GUI; just information on what the program is doing and an endline to type special commands. It doesn't seem this can be viewed unless you somehow left a terminal session entirely devoted to it, though... :\
|
|
|
|
10-25-2006, 02:11 AM
|
#7
|
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
There are some tools to interact with an interactive program like the one you describe there.
Search for "expect" for instance.
And yes, it'll probably require that you attach it to some terminal window. Running in background will make the program halt every time it asks you to type in some words.
Anyway, it is possible to send some commands to your program via stdin. Such technique is often used to script FTP sessions. See "here-doc" operator (<<) in Bash for instance.
|
|
|
|
10-26-2006, 01:35 AM
|
#8
|
|
Member
Registered: May 2006
Location: Cincinnati, Ohio
Distribution: Ubuntu
Posts: 256
Original Poster
Rep:
|
Quote:
|
Originally Posted by timmeke
There are some tools to interact with an interactive program like the one you describe there.
Search for "expect" for instance.
And yes, it'll probably require that you attach it to some terminal window. Running in background will make the program halt every time it asks you to type in some words.
Anyway, it is possible to send some commands to your program via stdin. Such technique is often used to script FTP sessions. See "here-doc" operator (<<) in Bash for instance.
|
Aahh... very good leads. I'll play around with it. This shouldn't be too tricky since the prog really just does its thing until I tell it to do something different... it never "prompts" for input, it just allows for it.
I'll mess around a bit when it's a more godly hour of the day.
|
|
|
|
12-13-2006, 09:11 AM
|
#9
|
|
Member
Registered: May 2006
Location: Cincinnati, Ohio
Distribution: Ubuntu
Posts: 256
Original Poster
Rep:
|
I ended up using "nohup", as it allowed the process to run in the background, simply and efficiently. However, now I've another problem: how can I bring the process back to the front? I can't find the job id, as both TOPS and lsof are not permitted at my userlevel on this system.
|
|
|
|
12-13-2006, 10:25 AM
|
#10
|
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
You could try the "jobs" command after you launch them in the backgroup, but the nohup may interfere with this (haven't tested it).
If it works, it'll print the job numbers for all running background processes and you can then use
fg %jobnr
to bring it to the foreground (once it's on foreground, use Ctrl-Z and "bg" to get it back to background).
Also, the $! variable should hold the process ID most recently executed background command.
So, if you start your commands like
Code:
nohup command1
pid1=$!
nohup command2
pid2=$!
...
then you should be able to access the processes via the different process IDs ($pid1, $pid2, etc).
|
|
|
|
12-13-2006, 06:27 PM
|
#11
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,988
|
FYI, in the cmd sequence
nohup prog &
it's the '&' that backgrounds a job.
'nohup' prevents a prog from terminating when you logout.
By default any job/process you start without 'nohup', even if it's backgrounded via '&', will terminate when you logout.
Backgrounded jobs are still associated with the initiating terminal, as you'll see if it prints to stdout/stderr, it'll appear in your terminal.
|
|
|
|
12-14-2006, 09:13 AM
|
#12
|
|
Member
Registered: May 2006
Location: Cincinnati, Ohio
Distribution: Ubuntu
Posts: 256
Original Poster
Rep:
|
Quote:
|
Originally Posted by timmeke
You could try the "jobs" command after you launch them in the backgroup, but the nohup may interfere with this (haven't tested it). If it works, it'll print the job numbers for all running background processes and you can then use
fg %jobnr
to bring it to the foreground (once it's on foreground, use Ctrl-Z and "bg" to get it back to background).
|
The nohup command does indeed interfere with that.  It lists nothing. To make sure I wasn't insane, I started a job ("man jobs" as it so happens) and used Ctrl+Z to stop it, then ran jobs again. This time it listed man jobs as a stopped process with id #1.
Quote:
|
Originally Posted by timmeke
Also, the $! variable should hold the process ID most recently executed background command.
So, if you start your commands like
Code:
nohup command1
pid1=$!
nohup command2
pid2=$!
...
then you should be able to access the processes via the different process IDs ($pid1, $pid2, etc).
|
After I figure out how to get this process, I'll make a script that does what you just described. Thanks.
Quote:
|
Originally Posted by chrism01
FYI, in the cmd sequence
nohup prog &
it's the '&' that backgrounds a job.
'nohup' prevents a prog from terminating when you logout.
By default any job/process you start without 'nohup', even if it's backgrounded via '&', will terminate when you logout.
Backgrounded jobs are still associated with the initiating terminal, as you'll see if it prints to stdout/stderr, it'll appear in your terminal.
|
Right. I had forgotten that.
Have any clue as to how I can get this sucker to the fg, chris? I can kill it instead of bringing it to the front; I don't care. I just need control of the app restored to me.
|
|
|
|
12-14-2006, 10:01 AM
|
#13
|
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
Maybe you could do something like:
Code:
your_ccommand &
disown -h
Disown seems to do prevent SIGHUP signals from the exiting shell too, but the -h options prevents deletion from the table of active jobs.
The $! trick may work too.
Reading up on job control in "man bash", I also found that "%%" and "%+" refer to the last background job.
Maybe you could try this too? Unfortunately, nohup probably interferes with this.
It's certainly possible to find all jobs detached from a terminal, but frankly, I doubt that there is a way to attach any random process, using its process ID, to your current terminal/shell so that you can view it's output.
|
|
|
|
12-14-2006, 11:43 AM
|
#14
|
|
Member
Registered: May 2006
Location: Cincinnati, Ohio
Distribution: Ubuntu
Posts: 256
Original Poster
Rep:
|
Quote:
|
Originally Posted by timmeke
Maybe you could do something like:
Code:
your_ccommand &
disown -h
Disown seems to do prevent SIGHUP signals from the exiting shell too, but the -h options prevents deletion from the table of active jobs.
The $! trick may work too.
Reading up on job control in "man bash", I also found that "%%" and "%+" refer to the last background job.
Maybe you could try this too? Unfortunately, nohup probably interferes with this.
It's certainly possible to find all jobs detached from a terminal, but frankly, I doubt that there is a way to attach any random process, using its process ID, to your current terminal/shell so that you can view it's output.
|
Executing the first command starts another instance of the program, which is no good; I need to get to the original instance already started. The second command returns "-bash: disown: current: no such job".
And yes, the referrers to the last background job are screwed up by nohup.
Last edited by RAdams; 12-14-2006 at 11:44 AM.
|
|
|
|
12-14-2006, 07:00 PM
|
#15
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,988
|
does fg built-in cmd work ?
fg [jobspec]
Resume jobspec in the foreground, and make it the current job.
If jobspec is not present, the shell’s notion of the current
job is used. The return value is that of the command placed
into the foreground, or failure if run when job control is dis-
abled or, when run with job control enabled, if jobspec does
not specify a valid job or jobspec specifies a job that was
started without job control.
if not, try
ps -ef|grep prog_name
and
kill pid_of_prog
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:07 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|