[ale] Bash: How to determine if called from cron?

Christopher Fowler cfowler at outpostsentinel.com
Mon Jun 27 10:07:39 EDT 2005


Maybe you need to check the where the Parent is sending its STDOUT?

ls -l /proc/`cat /proc/$$/stat | cut -d ' ' -f 4`/fd/1 | cut -d '>' -f2

On Mon, 2005-06-27 at 09:34, Christopher Fowler wrote:
> That won't work either.  I think tty does a isatty check.  My script
> that looks like this:
> 
> #!/bin/sh
> 
> FD1=`ls -l /proc/$$/fd/1 | cut -d '>' -f2`
> echo $FD1 >> /tmp/test.sh.out
> 
> Gave me this:
> [cfowler at cfowler tmp]$ tail /tmp/test.sh.out 
> pipe:[266205]
> pipe:[267448]
> pipe:[268442]
> pipe:[269312]
> 
> 
> On Mon, 2005-06-27 at 09:24, David A. De Graaf wrote:
> > On Mon, Jun 27, 2005 at 12:17:00AM -0400, 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? 
> > 
> > Read about the 'tty' command.
> > Try this example script, both manually and via cron:
> > 
> >   ANS=`tty`
> >   echo ANS: $ANS
> 
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale



More information about the Ale mailing list