Repository navigation
Expand file tree
/
Copy pathdebug.sh
More file actions
executable file
·76 lines (66 loc) · 2.06 KB
/
Copy pathdebug.sh
File metadata and controls
executable file
·76 lines (66 loc) · 2.06 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
# ------------------------------------------------------------
# debug.sh – debug scripts, e.g. non-interactive shell like cron
# ------------------------------------------------------------
# ------------------------------------------------------------
# Script/base dir
# ------------------------------------------------------------
get_base_dir() {
if [ -f "${0}" ]
then
# $0 points to a file on disk
printf '%s\n' "$(cd -- "$(dirname -- "${0}")" && pwd)"
else
# The script was sourced in a shell where $0 is not the script path
# Fallback to the current working directory
printf '%s\n' "$(pwd)"
fi
}
# ------------------------------------------------------------
# Main function to prevent occasional environment pollution
# ------------------------------------------------------------
closure() {
BASE_DIR="$(get_base_dir)"
# Load library
LIB_SH="${BASE_DIR}/lib.sh"
if [ ! -e "${LIB_SH}" ]
then
printf "${LIB_SH} does not exist, exiting\n"
exit 1
fi
# shellcheck source=lib.sh
if ! . "${LIB_SH}"
then
printf "Could not load ${LIB_SH}, exiting\n"
exit 1
fi
unset LIB_SH
# Do the job
cd "${BASE_DIR}"
environment
check_running
#set -x # debug
printf '%s\n' "Environment"
printf '%s\n' "------------------------------------------------------------"
env
printf '\n'
printf '%s\n' "User groups"
printf '%s\n' "------------------------------------------------------------"
groups
printf '\n'
RUNNING_VMS=""
RUNNING_VMS="$(virsh list --name --state-running)" || fail_internal "Failed to list running VMs"
for RUNNING_VM in ${RUNNING_VMS}
do
printf 'VM: %s\n' "${RUNNING_VM}"
DISKS=""
DISKS="$(get_vm_disk_names_and_absolute_paths "${RUNNING_VM}")" || fail_internal "Could not get disk list for ${RUNNING_VM}"
for DISK in ${DISKS}
do
printf '\t%s\n' "${DISK}"
done
unset DISKS
done
unset RUNNING_VMS
}
closure