Double quote to prevent globbing and word splitting.

Do not use legacy backticks.
Proper use of printf
Do not use wc -l with grep, instead use grep -c
Use pgrep

Signed-off-by: Werner Buck <wernerbuck@gmail.com>
This commit is contained in:
Werner Buck 2015-05-29 13:42:34 +02:00
parent 54202b3b41
commit f4aab9c8c5
9 changed files with 87 additions and 87 deletions

View file

@ -14,21 +14,20 @@
. ./helper_lib.sh
# Setup the paths
this_path=$(abspath $0) ## Path of this file including filenamel
dir_name=`dirname ${this_path}` ## Dir where this file is
myname=`basename ${this_path}` ## file name of this script.
logger="${myname}.log"
this_path=$(abspath "$0") ## Path of this file including filenamel
myname=$(basename "${this_path}") ## file name of this script.
export PATH=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin/
logger="${myname}.log"
# Check for required program(s)
req_progs='docker netstat grep awk'
for p in $req_progs; do
command -v $p >/dev/null 2>&1 || { printf "$p command not found.\n"; exit 1; }
command -v "$p" >/dev/null 2>&1 || { printf "%s command not found.\n" "$p"; exit 1; }
done
# Ensure we can connect to docker daemon
`docker ps -q >/dev/null 2>&1`
docker ps -q >/dev/null 2>&1
if [ $? -ne 0 ]; then
printf "Error connecting to docker daemon (does docker ps work?)\n"
exit 1
@ -36,9 +35,9 @@ fi
usage () {
printf "
usage: $myname [options]
usage: %s [options]
-h optional Print this help message\n"
-h optional Print this help message\n" "$myname"
exit 1
}
@ -51,10 +50,10 @@ yell "# ------------------------------------------------------------------------
# https://benchmarks.cisecurity.org/tools2/docker/CIS_Docker_1.6_Benchmark_v1.0.0.pdf
# ------------------------------------------------------------------------------"
logit "Initializing `date`\n"
logit "Initializing $(date)\n"
# Warn if not root
ID=`id -u`
ID=$(id -u)
if [ "x$ID" != "x0" ]; then
warn "Some tests might require root to run"
sleep 3
@ -73,19 +72,19 @@ done
# Load all the tests from tests/ and run them
main () {
# List all running containers
containers=`docker ps -q`
containers=$(docker ps -q)
# If there is a container with label docker-bench, memorize it:
benchcont="nil"
for c in $containers; do
labels=`docker inspect --format '{{ .Config.Labels }}' $c`
labels=$(docker inspect --format '{{ .Config.Labels }}' "$c")
contains "$labels" "docker-bench" && benchcont="$c"
done
# List all running containers except docker-bench
containers=`docker ps -q | grep -v $benchcont`
containers=$(docker ps -q | grep -v "$benchcont")
for test in tests/*.sh
do
. ./$test
. ./"$test"
done
}