Progetto Backup DB

Da wiki.gienne.cloud.

Verifica Sistema operativo per gestire eccezioni:

#!/bin/bash
case "$OSTYPE" in
  solaris*) echo "SOLARIS" ;;
  darwin*)  echo "OSX" ;;
  linux*)   echo "LINUX" ;;
  bsd*)     echo "BSD" ;;
  msys*)    echo "WINDOWS" ;;
  aix*)     echo "AIX" ;;
  *)        echo "unknown: $OSTYPE" ;;
esac


Lettura parametri:

#!/bin/bash

POSITIONAL=()
while  $# -gt 0 
do
key="$1"

case $key in
    -e|--extension)
    EXTENSION="$2"
    shift # past argument
    shift # past value
    ;;
    -s|--searchpath)
    SEARCHPATH="$2"
    shift # past argument
    shift # past value
    ;;
    -l|--lib)
    LIBPATH="$2"
    shift # past argument
    shift # past value
    ;;
    --default)
    DEFAULT=YES
    shift # past argument
    ;;
    *)    # unknown option
    POSITIONAL+=("$1") # save it in an array for later
    shift # past argument
    ;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters

echo "FILE EXTENSION  = ${EXTENSION}"
echo "SEARCH PATH     = ${SEARCHPATH}"
echo "LIBRARY PATH    = ${LIBPATH}"
echo "DEFAULT         = ${DEFAULT}"
echo "Number files in SEARCH PATH with EXTENSION:" $(ls -1 "${SEARCHPATH}"/*."${EXTENSION}" | wc -l)
if  -n $1 ; then                                            
    echo "Last line of file specified as non-opt/last argument:"
    tail -1 "$1"                                                
fi

Esempio di lancio:

Example: demo-space-separated.sh -e conf -s /etc -l /usr/lib /etc/hosts  

Esempio di output:

FILE EXTENSION  = conf                                                                                           
SEARCH PATH     = /etc                               
LIBRARY PATH    = /usr/lib                           
DEFAULT         =                                    
Number files in SEARCH PATH with EXTENSION: 14       
Last line of file specified as non-opt/last argument:
#93.184.216.34    example.com