LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Easiest CRON Question in the World (https://www.linuxquestions.org/questions/linux-software-2/easiest-cron-question-in-the-world-494967/)

RAdams 10-23-2006 06:49 PM

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?

anomie 10-23-2006 08:09 PM

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?

RAdams 10-24-2006 03:11 AM

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.

timmeke 10-24-2006 05:34 AM

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.

nonkey 10-24-2006 07:06 AM

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

RAdams 10-25-2006 01:54 AM

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... :\

timmeke 10-25-2006 02:11 AM

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.

RAdams 10-26-2006 01:35 AM

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.

RAdams 12-13-2006 09:11 AM

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.

timmeke 12-13-2006 10:25 AM

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

chrism01 12-13-2006 06:27 PM

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.

RAdams 12-14-2006 09:13 AM

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. :cry: 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. :o

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.

timmeke 12-14-2006 10:01 AM

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.

RAdams 12-14-2006 11:43 AM

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.

chrism01 12-14-2006 07:00 PM

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


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