One option is to check if the script is bound to tty.
#!/bin/sh if [ -t 0 ]; then echo "I'm on a TTY, this is interactive." else logger "My output may get emailed, or may not. Let log things instead." fi
Note that jobs launched by at(1) also run without tty, but not specifically with cron.
Please note that this is POSIX, not Linux- (or bash-).
ghoti source share