[ale] Bash: How to determine if called from cron?
Christopher Fowler
cfowler at outpostsentinel.com
Mon Jun 27 08:51:00 EDT 2005
Cron output is stored into a temp file in /tmp. You can stat STDOUT and
see what filename is for that descriptor. If the filename contains the
word 'cron' then you are inside cron.
The only problem there is I know how to do this in C. Uoi can do it in
perl but I have no clue how to in bash.
You might be able to do something like this:
LOCATION=`perl <<EOF
......
EOF
`
Then check the value of that variable.
Or maybe this will work in bash
[cfowler at cfowler cfowler]$ FD1=`ls -l /proc/$$/fd/1 | cut -d '>' -f2`;
[cfowler at cfowler cfowler]$ echo $FD1
/dev/pts/1
You'll want to check FD1 for the word cron.
On Mon, 2005-06-27 at 00:17, Christopher Bergeron wrote:
> Does anyone know of an easy way for my script to determine if it's being
> run from cron or from a user shell?
>
> I have a feeling theres an easy way to do this, but I'm drawing a
> complete blank right now. I'm looking at my Environment vars, but I'm
> not sure what gets set by Cron when it runs a script.
>
> Any ideas are much appreciated...
>
> Kind regards,
> CB
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list