-
Notifications
You must be signed in to change notification settings - Fork 0
/
lxm-ls.sh
executable file
·61 lines (53 loc) · 1.2 KB
/
lxm-ls.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
52
53
54
55
56
57
58
59
60
#!/bin/bash
# show help
function show_help {
echo "usage: lxm ls [-h] [-F] [-g <groups>] [<filter>]"
echo ""
echo "lxcManager: lxm-ls - list container(s)"
echo ""
echo "positional arguments:"
echo " <filter> regexp to be applied on the container list"
echo ""
echo "optional arguments:"
echo " -h show this help message and exit"
echo " -g <groups> groups (comma separated) the container must be a member of"
echo " -F show all fields"
}
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize default variable(s)
fancy="-f"
# parse arguments
while getopts "hg:F" opt; do
case "$opt" in
h) # show help
show_help
exit 0
;;
g) # regex to filter for group
groups=$OPTARG
;;
F)
fancy="-F name,state,interfaces,ipv4,ipv6,pid,memory,ram,swap,groups,autostart -f"
;;
\?) # unrecognized option
exit 1
;;
:) # missing argument
exit 1
;;
esac
done
shift $((OPTIND-1))
# exit if more than one argument is left
if [[ ! -z ${@:2} ]]; then
show_help
exit 1
fi
# print filtered output of lxc-ls -f
filter="$1"
if [[ -z $groups ]]; then
lxc-ls $fancy "$filter"
else
lxc-ls $fancy "$filter" -g "$groups"
fi