add some logging
This commit is contained in:
@@ -4,11 +4,14 @@ source functions.sh
|
|||||||
|
|
||||||
pidfile=/var/run/backup_script
|
pidfile=/var/run/backup_script
|
||||||
|
|
||||||
|
mylog 0 "backup starts"
|
||||||
|
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
function cleanup {
|
function cleanup {
|
||||||
echo "bye bye"
|
echo "bye bye"
|
||||||
test -f $pidfile && rm -f $pidfile
|
test -f $pidfile && rm -f $pidfile
|
||||||
|
mylog 0 "backup done"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -f $pidfile ] ; then
|
if [ -f $pidfile ] ; then
|
||||||
@@ -53,7 +56,8 @@ shift $(( OPTIND - 1))
|
|||||||
mkdir -p $backupdir || myerror 2 "impossible de créer $backupdir"
|
mkdir -p $backupdir || myerror 2 "impossible de créer $backupdir"
|
||||||
|
|
||||||
for dir in "$@" ; do
|
for dir in "$@" ; do
|
||||||
test -d $dir || { echo $dir dont exist ; continue ; }
|
test -d $dir || { echo $dir dont exist ; mylog 2 "$dir dont exists" ; continue ; }
|
||||||
echo cp -a $dir $backupdir
|
echo cp -a $dir $backupdir
|
||||||
|
mylog $? "backup of $dir done"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
12
functions.sh
12
functions.sh
@@ -1,4 +1,16 @@
|
|||||||
#/home/usera/functions.sh
|
#/home/usera/functions.sh
|
||||||
|
|
||||||
|
function mylog {
|
||||||
|
code=$1
|
||||||
|
message=$2
|
||||||
|
if [ $code -eq 0 ] ; then
|
||||||
|
code="info"
|
||||||
|
else
|
||||||
|
code="error"
|
||||||
|
fi
|
||||||
|
logger -p local1.$code "$message"
|
||||||
|
}
|
||||||
|
|
||||||
function myerror {
|
function myerror {
|
||||||
code=$1
|
code=$1
|
||||||
shift
|
shift
|
||||||
|
|||||||
Reference in New Issue
Block a user