Test if script is launched from cron or CL
Disclaimer: I, like many, am not a programmer, but I can grasp things with help.
I'm trying to develop yet another way to copy files from a server to external media. I want to be able to test whether it's running from cron or the command line. The command line test seems fairly obvious: If the script is run manually with no arguments then show usage. (I'll work out how to restrict this to a date format before I put it in production.) Below is the first step that creates a directory structure to move the archive to. It's incomplete still but the idea is that it will create a date-based directory name. It seems the cron test needs to happen before the while loop. Code:
#!/bin/bash Thanks, Andrew |
Quote:
|
Quote:
I will be testing for either cron or crond depending on distro implementation, apparently. SuSE and Ubuntu both use cron, and CentOS uses crond, for example. Thanks for the clarity! Andrew |
You can also use the -t test ( http://www.tldp.org/LDP/abs/html/fto.html ) to check if stdin/stdout is associated to a terminal (false if run from cron)
|
Quote:
Thanks again. Andrew |
All times are GMT -5. The time now is 07:58 PM. |