File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change 1- # Function below creates a backup of a file. Returns non-zero status on error.
1+ #! /bin/bash
2+
3+ log () {
4+ # This function sends a message to syslog and to standard output if VERBOSE is true.
5+
6+ local MESSAGE=" ${@ } "
7+ if [[ " ${VERBOSE} " = ' true' ]]
8+ then
9+ echo " ${MESSAGE} "
10+ fi
11+ logger -t backup_file.sh " ${MESSAGE} "
12+ }
213
14+ # Function below creates a backup of a file. Returns non-zero status on error.
315backup_file () {
416 local FILE=" ${1} "
5- if [[ -f " {FILE}" ]]
17+ if [[ -f " $ {FILE}" ]]
618 then
7- local BACKUP_FILE=" /var/tmp/$( basename ${FILE} ) .& (date +%F-%N)"
19+ local BACKUP_FILE=" /var/tmp/$( basename ${FILE} ) .$ ( date +%F-%N) "
820 log " Backing up ${FILE} to ${BACKUP_FILE} "
921
1022 cp -p ${FILE} ${BACKUP_FILE}
@@ -14,4 +26,14 @@ backup_file() {
1426 fi
1527}
1628
29+ readonly VERBOSE=' true'
1730backup_file ' /etc/passwd'
31+
32+ # A decision based exit status of the function.
33+ if [[ " ${?} " -eq ' 0' ]]
34+ then
35+ log ' File backup succeeded!'
36+ else
37+ log ' File backup failed!'
38+ exit 1
39+ fi
You can’t perform that action at this time.
0 commit comments