API
1
Hello all,
I have a question regarding the difference betwen cron and command line.
What I would like to do is to print a statement into a logfile if a script has been executed from cron or from command line.
It should be as:
#!/bin/bash
if <Check if this script has been executed by cron or commandline>; then
echo "Cron" >> $logfile
else
echo "Commandline" >> $logfile
fi
You could test if you are on a terminal or pseudo terminal which would indicate a command line user. Having neither would suggest a scheduler.
The output from ps -otty= -p $$
will give you this.
I hope that this helps,
Robin
1 Like
API
3
Hi Robin,
yes, this works fine. Tx for your quick response.
RudiC
4
You might check for your shell's -i
(interactive) option by testing the $-
parameter.
1 Like