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.
# Set DirDate1 from command line
# Set DirDate2 for use from cron
# cron test here?
# Test whether external device is mounted and capture mount exit code
if /mnt/external/server_backups !exist then
) test exit code to do some other stuff that I can't find my notes on
and email my phone if mount fails.
while [ "$DirDate1" = "" ] # test for arguments
do # echo usage
case "$1" in
"") echo >&2 \
Creates backup directory structure with
date input as part of directory name, then
performs selective copy.
usage: $0 [yyyymmdd]
# DirDate must be enclosed in double quotes
# rsync stuff will go here when I get it figured out and tested
So, how would you all suggest I test if the script is being launched from cron? It's probably right in front of my face, which is why I can't see it....