-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsection-6b.sh
executable file
·51 lines (43 loc) · 1.04 KB
/
section-6b.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
log() {
# This function sends a message to syslog and to standard output if VERBOSE is true.
local MESSAGE="${@}"
if [[ "${VERBOSE}" = 'true' ]]
then
echo "${MESSAGE}"
fi
logger -t section-6a.sh "${MESSAGE}"
}
perform_backup() {
# This function creates a backup of a file. Returns non-zero status on error.
local FILE="${1}"
echo "${FILE}"
# Make sure the file exists.
if [[ -f "${FILE}" ]]
then
local BACKUP_FILE="/var/tmp/$(basename ${FILE}).$(date +%F-%N)"
log "Backing up ${FILE} to ${BACKUP_FILE}"
# The exit status of the function will be the exit status of the cp command.
cp -p ${FILE} ${BACKUP_FILE}
else
# The file does not exist, so returns a non-zero exit status.
return 1
fi
}
check_backup() {
# Make a decision based on the exit status of the function
if [[ "${?}" -eq '0' ]]
then
log 'File backup succeeded!'
else
log 'File backup failed!'
exit 1
fi
}
backup_file() {
#
perform_backup "${1}"
check_backup
}
readonly VERBOSE=true
backup_file "${1}"