I am using getopts in a script as it can perform either FTP or RSYNC backup. when running the FTP portion it will create a tarball and as long as it is not run in -n (no kill) it will also verify and encrypt the tarball before FTP across the LAN.
I want to set the script so that if there is no option provided it does not run, but will echo a warning that -f, -r, -n, -o, -s must be called with the script.
Code:
### This file MUST be called with one of the following options.
### -n will start the script in test mode not terminating any interfaces.
### -r will start the rsync vs of the script
### -f will start the ftp vs of the sctipt
### -x will start the script in debug mode bash -xvv
### -s will run the setup portion of the script and must be run first.
### -o will print out the options
### Options
###################################
while getopts ":nrfxso" opt
do
case $opt in
n ) NO_KILL=true
;;
r ) DO_FTP=false
DO_RSYNC=true
DO_TAR=false
;;
f ) DO_FTP=true
DO_RSYNC=false
DO_TAR=true
;;
x ) set -xvv
;;
s ) DO_SETUP=true
;;
o ) DO_USE=true
;;
esac
done
shift $(( $OPTIND -1 ))
USAGE()
{
cat <<-usage
This is a test to evaluate this function. To run this script you must first run it
with the -s option. During the setup you will be able to choose FTP or RSYNC for backups.
You may run the setup portion more then one time if you wish to use both FTP & RSYNC.
Once the script is setup you must call with either -n, -r, -f, or any combination.
ex: BACKUP -f -r
this will run the FTP portion of the script first, then RSYNC after the
FTP is complete. It will terminate all Rx30 screens and interfaces then
restart them after RSYNC has completed. It will also remove any tarballs
left in the /tmp directory on the server.
ex: BACKUP -f -n
this will run the FTP portion of the script in TEST mode not terminating
any rx30 screen or interface. It will also not encrypt the tarball.
ex: BACKUP -f -r -x
Now you will run just like the first example, but it will be run in full
debug mode. $ bash -xvv BACKUP -f -r
usage
}
Not sure i explained that correctly. hope i did.