Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Nov 2005 21:30:02 +0000
From:      Alex Zbyslaw <xfb52@dial.pipex.com>
To:        freebsd-questions@freebsd.org,  gerard@seibercom.net
Subject:   Re: Viewing Programs Running From CRON
Message-ID:  <4387825A.4040307@dial.pipex.com>
In-Reply-To: <20051125153642.2B05.GERARD@seibercom.net>
References:  <20051125153642.2B05.GERARD@seibercom.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Gerard Seibert wrote:

>I have asked many dumb questions before, and this will no doubt add to
>the list.
>
>Scenario:
>
>I start a program from CRON. As an example, let us use
>/sysutils/portmanager. Now this program is being run in the background.
>How do I get it to run in the foreground so that I can view what it is
>doing, and or stop it if I want to? If I succeed in that maneuver, can I
>place it in the background again?
>  
>
I'm not aware of any way to do what you are asking, though maybe it can 
be done though /proc, I'm not sure.  See man procfs if you want to 
experiment.

Instead, why don't you make the cron job redirect output to a file e.g.
    /sysutils/portmanager 2>&1 | tee /tmp/portmanager

That way you can do a tail -f on /tmp/portmanager and still get the 
output mailed you as normal.  If you don't want to be mailed the output 
then just use > in place of | tee.

If more than one such job might run at once then you'll have to find 
some way to name the file differently for each run.  Calling it 
/tmp/portmanager.$$ would probably work as each invocation should be run 
using a different shell process.  I haven't tested this :-(

--Alex

PS Background isn't really an accurate description of the process 
running from cron.  What you are trying to do is to see STDOUT and 
STDERR from some process which is unrelated to the interactive shell you 
are running.  A background process, as you've probably come across it, 
is a process run from your shell but which doesn't stop you interacting 
with the shell.  In this case the shell is able to send STDOUT and 
STDERR from the process to your terminal, but the job run from cron has 
no such terminal.  A better description would be a daemon.  Probably not 
explained very well, and no doubt someone can correct the details.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4387825A.4040307>