From af7b2c3a9cdfd510f06e8dc984b2cde79bf54023 Mon Sep 17 00:00:00 2001 From: Rawiri Blundell Date: Mon, 10 Jun 2019 10:31:46 +1200 Subject: [PATCH] Linux Agent: Update all instances of '[...]' to '[[...]]' --- agents/check_mk_agent.linux | 188 ++++++++++++++++++------------------ 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux index 5eb50102a4a..f02403fd4e4 100755 --- a/agents/check_mk_agent.linux +++ b/agents/check_mk_agent.linux @@ -37,9 +37,9 @@ export MK_VARDIR=${MK_VARDIR:-/var/lib/check_mk_agent} # Provide information about the remote host. That helps when data # is being sent only once to each remote host. -if [ "$REMOTE_HOST" ]; then +if [[ "$REMOTE_HOST" ]]; then export REMOTE=$REMOTE_HOST -elif [ "$SSH_CLIENT" ]; then +elif [[ "$SSH_CLIENT" ]]; then export REMOTE=${SSH_CLIENT%% *} fi @@ -69,15 +69,15 @@ SPOOLDIR=$MK_VARDIR/spool # When the nodes agent is executed by a e.g. docker node in a container, # then don't close stdin, because the agent is piped through it in this # case. -if [ "$1" = -d ]; then +if [[ "$1" = -d ]]; then set -xv -elif [ -z "$MK_FROM_NODE" ]; then +elif [[ -z "$MK_FROM_NODE" ]]; then exec /dev/null fi # Detect whether or not the agent is being executed in a container # environment. -if [ -f /.dockerenv ]; then +if [[ -f /.dockerenv ]]; then IS_DOCKERIZED=1 elif grep container=lxc /proc/1/environ >/dev/null 2>&1; then # Works in lxc environment e.g. on Ubuntu bionic, but does not @@ -107,19 +107,19 @@ if inpath timeout; then export -f waitmax fi -if [ -f "$MK_CONFDIR/encryption.cfg" ]; then +if [[ -f "$MK_CONFDIR/encryption.cfg" ]]; then # shellcheck source=/dev/null . "$MK_CONFDIR/encryption.cfg" fi -if [ "$ENCRYPTED" == "yes" ]; then +if [[ "$ENCRYPTED" == "yes" ]]; then echo -n "00" # protocol version exec > >(openssl enc -aes-256-cbc -md md5 -k "$PASSPHRASE" -nosalt) fi RTC_PLUGINS="" -if [ -e "$MK_CONFDIR/real_time_checks.cfg" ]; then +if [[ -e "$MK_CONFDIR/real_time_checks.cfg" ]]; then # shellcheck source=/dev/null . "$MK_CONFDIR/real_time_checks.cfg" fi @@ -130,7 +130,7 @@ fi # section_mem() { - if [ -z "$IS_DOCKERIZED" ]; then + if [[ -z "$IS_DOCKERIZED" ]]; then echo '<<>>' grep -E -v '^Swap:|^Mem:|total:' < /proc/meminfo else @@ -145,21 +145,21 @@ section_mem() { } section_cpu() { - if [ "$(uname -m)" = "armv7l" ]; then + if [[ "$(uname -m)" = "armv7l" ]]; then CPU_REGEX='^processor' else CPU_REGEX='^CPU|^processor' fi NUM_CPUS=$(grep -c -E $CPU_REGEX < /proc/cpuinfo) - if [ -z "$IS_DOCKERIZED" ] && [ -z "$IS_LXC_CONTAINER" ]; then + if [[ -z "$IS_DOCKERIZED" ]]&&[[ -z "$IS_LXC_CONTAINER" ]]; then echo '<<>>' echo "$(cat /proc/loadavg) $NUM_CPUS" - if [ -f "/proc/sys/kernel/threads-max" ]; then + if [[ -f "/proc/sys/kernel/threads-max" ]]; then cat /proc/sys/kernel/threads-max fi else - if [ -n "$IS_DOCKERIZED" ]; then + if [[ -n "$IS_DOCKERIZED" ]]; then echo '<<>>' else echo '<<>>' @@ -172,7 +172,7 @@ section_cpu() { section_uptime() { echo '<<>>' - if [ -z "$IS_DOCKERIZED" ]; then + if [[ -z "$IS_DOCKERIZED" ]]; then cat /proc/uptime else echo "$(($(date +%s) - $(stat -c %Z /dev/pts)))" @@ -186,7 +186,7 @@ section_uptime() { # thousands of agent processes and, ultimately, a dead monitored system. # These should generally be monitored on the NFS server, not on the clients. section_df() { - if [ -n "$IS_DOCKERIZED" ]; then + if [[ -n "$IS_DOCKERIZED" ]]; then return fi @@ -194,7 +194,7 @@ section_df() { # -l should hide any remote FS but seems to be all but working. local excludefs excludefs="-x smbfs -x cifs -x iso9660 -x udf -x nfsv4 -x nfs -x mvfs -x prl_fs -x squashfs" - if [ -n "$IS_LXC_CONTAINER" ]; then + if [[ -n "$IS_LXC_CONTAINER" ]]; then excludefs+=" -x zfs" fi @@ -250,16 +250,16 @@ run_cached () { local append_age=0 # TODO: this function is unable to handle mulitple args at once # for example: -s -m won't work, it is read as single token "-s -m" - if [ "$1" = -s ]; then local section="echo '<<<$2:cached($NOW,$3)>>>' ; " ; shift ; fi - if [ "$1" = -m ]; then local mrpe=1 ; shift ; fi - if [ "$1" = "-ma" ]; then local mrpe=1 ; local append_age=1 ; shift ; fi + if [[ "$1" = -s ]]; then local section="echo '<<<$2:cached($NOW,$3)>>>' ; " ; shift ; fi + if [[ "$1" = -m ]]; then local mrpe=1 ; shift ; fi + if [[ "$1" = "-ma" ]]; then local mrpe=1 ; local append_age=1 ; shift ; fi local NAME=$1 local MAXAGE=$2 shift 2 local CMDLINE=$section$* - if [ ! -d "$MK_VARDIR/cache" ]; then mkdir -p "$MK_VARDIR/cache" ; fi - if [ "$mrpe" = 1 ]; then + if [[ ! -d "$MK_VARDIR/cache" ]]; then mkdir -p "$MK_VARDIR/cache" ; fi + if [[ "$mrpe" = 1 ]]; then CACHEFILE="$MK_VARDIR/cache/mrpe_$NAME.cache" else CACHEFILE="$MK_VARDIR/cache/$NAME.cache" @@ -269,10 +269,10 @@ run_cached () { # process if the age (access time) of $CACHEFILE.new is twice the MAXAGE. # Output the evantually already cached section anyways and start the cache # update again. - if [ -e "$CACHEFILE.new" ]; then + if [[ -e "$CACHEFILE.new" ]]; then local CF_ATIME CF_ATIME=$(stat -c %X "$CACHEFILE.new") - if [ $((NOW - CF_ATIME)) -ge $((MAXAGE * 2)) ]; then + if [[ $((NOW - CF_ATIME)) -ge $((MAXAGE * 2)) ]]; then # Kill the process still accessing that file in case # it is still running. This avoids overlapping processes! fuser -k -9 "$CACHEFILE.new" >/dev/null 2>&1 @@ -282,15 +282,15 @@ run_cached () { # Check if cache file exists and is recent enough - if [ -s "$CACHEFILE" ]; then + if [[ -s "$CACHEFILE" ]]; then local MTIME MTIME=$(stat -c %Y "$CACHEFILE") local AGE AGE=$((NOW - MTIME)) - if [ "$AGE" -le "$MAXAGE" ]; then local USE_CACHEFILE=1 ; fi + if [[ "$AGE" -le "$MAXAGE" ]]; then local USE_CACHEFILE=1 ; fi # Output the file in any case, even if it is # outdated. The new file will not yet be available - if [ $append_age -eq 1 ]; then + if [[ $append_age -eq 1 ]]; then # insert the cached-string before the pipe (first -e) # or, if no pipe found (-e t) append it (third -e), # but only once and on the second line (2!b) (first line is section header, @@ -309,9 +309,9 @@ run_cached () { fi # Cache file outdated and new job not yet running? Start it - if [ -z "$USE_CACHEFILE" ] && [ ! -e "$CACHEFILE.new" ]; then + if [[ -z "$USE_CACHEFILE" ]]&&[[ ! -e "$CACHEFILE.new" ]]; then # When the command fails, the output is throws away ignored - if [ $mrpe -eq 1 ]; then + if [[ $mrpe -eq 1 ]]; then echo "set -o noclobber ; exec > \"$CACHEFILE.new\" || exit 1 ; run_mrpe $NAME \"$CMDLINE\" && mv \"$CACHEFILE.new\" \"$CACHEFILE\" || rm -f \"$CACHEFILE\" \"$CACHEFILE.new\"" | nohup /bin/bash >/dev/null 2>&1 & else echo "set -o noclobber ; exec > \"$CACHEFILE.new\" || exit 1 ; $CMDLINE && mv \"$CACHEFILE.new\" \"$CACHEFILE\" || rm -f \"$CACHEFILE\" \"$CACHEFILE.new\"" | nohup /bin/bash >/dev/null 2>&1 & @@ -330,12 +330,12 @@ run_real_time_checks() { echo $$ > "$PIDFILE" - if [ "$PASSPHRASE" != "" ]; then + if [[ "$PASSPHRASE" != "" ]]; then # new mechanism to set the passphrase has priority RTC_SECRET=$PASSPHRASE fi - if [ "$ENCRYPTED_RT" != "no" ]; then + if [[ "$ENCRYPTED_RT" != "no" ]]; then PROTOCOL=00 else PROTOCOL=99 @@ -344,7 +344,7 @@ run_real_time_checks() { while true; do # terminate when pidfile is gone or other Real-Time Check process started or configured timeout - if [ ! -e "$PIDFILE" ] || [ "$(<"$PIDFILE")" -ne $$ ] || [ "$RTC_TIMEOUT" -eq 0 ]; then + if [[ ! -e "$PIDFILE" ]]||[[ "$(<"$PIDFILE")" -ne $$ ]]||[[ "$RTC_TIMEOUT" -eq 0 ]]; then exit 1 fi @@ -355,7 +355,7 @@ run_real_time_checks() { # dd is used to concatenate the output of all commands to a single write/block => udp packet { echo -n $PROTOCOL ; date +%s | tr -d '\n' ; - if [ "$ENCRYPTED_RT" != "no" ]; then + if [[ "$ENCRYPTED_RT" != "no" ]]; then export RTC_SECRET=$RTC_SECRET ; section_"$SECTION" | openssl enc -aes-256-cbc -md md5 -pass env:RTC_SECRET -nosalt ; else section_"$SECTION" ; @@ -367,7 +367,7 @@ run_real_time_checks() { # Plugins if cd "$PLUGINSDIR"; then for PLUGIN in $RTC_PLUGINS; do - if [ ! -f $PLUGIN ]; then + if [[ ! -f $PLUGIN ]]; then continue fi @@ -377,7 +377,7 @@ run_real_time_checks() { # dd is used to concatenate the output of all commands to a single write/block => udp packet { echo -n $PROTOCOL ; date +%s | tr -d '\n' ; - if [ "$ENCRYPTED_RT" != "no" ]; then + if [[ "$ENCRYPTED_RT" != "no" ]]; then export RTC_SECRET=$RTC_SECRET ; ./$PLUGIN | openssl enc -aes-256-cbc -md md5 -pass env:RTC_SECRET -nosalt ; else ./"$PLUGIN"; @@ -402,7 +402,7 @@ echo "PluginsDirectory: $PLUGINSDIR" echo "LocalDirectory: $LOCALDIR" # If we are called via xinetd, try to find only_from configuration -if [ -n "$REMOTE_HOST" ]; then +if [[ -n "$REMOTE_HOST" ]]; then echo -n 'OnlyFrom: ' sed -n '/^service[[:space:]]*'$XINETD_SERVICE_NAME'/,/}/s/^[[:space:]]*only_from[[:space:]]*=[[:space:]]*\(.*\)/\1/p' /etc/xinetd.d/* | head -n1; echo fi @@ -430,7 +430,7 @@ if inpath waitmax; then sed -n '/ nfs4\? /s/[^ ]* \([^ ]*\) .*/\1/p' < /proc/mounts | sed 's/\\040/ /g' | while read -r MP; do - if [ "$STAT_VERSION" != "$STAT_BROKE" ]; then + if [[ "$STAT_VERSION" != "$STAT_BROKE" ]]; then waitmax -s 9 5 stat -f -c "$MP ok %b %f %a %s" "$MP" || \ echo "$MP hanging 0 0 0 0" else @@ -443,9 +443,9 @@ if inpath waitmax; then sed -n '/ cifs\? /s/[^ ]* \([^ ]*\) .*/\1/p' < /proc/mounts | sed 's/\\040/ /g' | while read -r MP; do - if [ ! -r "$MP" ]; then + if [[ ! -r "$MP" ]]; then echo "$MP Permission denied" - elif [ "$STAT_VERSION" != "$STAT_BROKE" ]; then + elif [[ "$STAT_VERSION" != "$STAT_BROKE" ]]; then waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" || \ echo "$MP hanging 0 0 0 0" else @@ -494,7 +494,7 @@ fi # Current state of bonding interfaces -if [ -e /proc/net/bonding ]; then +if [[ -e /proc/net/bonding ]]; then echo '<<>>' pushd /proc/net/bonding > /dev/null head -v -n 1000 ./* @@ -517,7 +517,7 @@ fi if inpath waitmax; then echo '<<>>' THIS=$(waitmax 5 cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | awk ' /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } }') - if [ $? == 0 ]; then + if [[ $? == 0 ]]; then echo "$THIS" elif inpath ss; then ss -ant |grep -v ^State | awk ' /:/ { c[$1]++; } END { for (x in c) { print x, c[x]; } }' \ @@ -527,14 +527,14 @@ fi # Linux Multipathing if inpath multipath; then - if [ -f /etc/multipath.conf ]; then + if [[ -f /etc/multipath.conf ]]; then echo '<<>>' multipath -l fi fi # Performancecounter Platten -if [ -z "$IS_DOCKERIZED" ]; then +if [[ -z "$IS_DOCKERIZED" ]]; then echo '<<>>' date +%s grep -E ' (x?[shv]d[a-z]*[0-9]*|cciss/c[0-9]+d[0-9]+|emcpower[a-z]+|dm-[0-9]+|VxVM.*|mmcblk.*|dasd[a-z]*|bcache[0-9]+|nvme[0-9]+n[0-9]+) ' < /proc/diskstats @@ -542,7 +542,7 @@ if [ -z "$IS_DOCKERIZED" ]; then echo '[dmsetup_info]' dmsetup info -c --noheadings --separator ' ' -o name,devno,vg_name,lv_name fi - if [ -d /dev/vx/dsk ]; then + if [[ -d /dev/vx/dsk ]]; then echo '[vx_dsk]' stat -c "%t %T %n" /dev/vx/dsk/*/* fi @@ -563,7 +563,7 @@ fi # Performancecounter Kernel -if [ -z "$IS_DOCKERIZED" ] && [ -z "$IS_LXC_CONTAINER" ]; then +if [[ -z "$IS_DOCKERIZED" ]]&&[[ -z "$IS_LXC_CONTAINER" ]]; then echo '<<>>' date +%s cat /proc/vmstat /proc/stat @@ -597,7 +597,7 @@ if (type ipmi-sensors && ls /dev/ipmi*) &>/dev/null; then run_cached -s ipmi_sensors 300 "for class in Temperature Power_Unit Fan; do ipmi-sensors $IPMI_FORMAT --sdr-cache-directory /var/cache $IPMI_GROUP_OPT \"\$class\" | sed -e 's/ /_/g' -e 's/:_\?/ /g' -e 's@ \([^(]*\)_(\([^)]*\))@ \2_\1@' # In case of a timeout immediately leave loop. - if [ $? = 255 ]; then break ; fi + if [[ $? = 255 ]]; then break ; fi done" fi @@ -646,7 +646,7 @@ else MegaCli_bin="unknown" fi -if [ "$MegaCli_bin" != "unknown" ]; then +if [[ "$MegaCli_bin" != "unknown" ]]; then echo '<<>>' for part in $($MegaCli_bin -EncInfo -aALL -NoLog < /dev/null \ | sed -rn 's/:/ /g; s/[[:space:]]+/ /g; s/^ //; s/ $//; s/Number of enclosures on adapter ([0-9]+).*/adapter \1/g; /^(Enclosure|Device ID|adapter) [0-9]+$/ p'); do @@ -692,7 +692,7 @@ fi # OpenVPN Clients. Currently we assume that the configuration # is in # /etc/openvpn. We might find a safer way to find the configuration later. -if [ -e /etc/openvpn/openvpn-status.log ]; then +if [[ -e /etc/openvpn/openvpn-status.log ]]; then echo '<<>>' sed -n -e '/CLIENT LIST/,/ROUTING TABLE/p' < /etc/openvpn/openvpn-status.log \ | sed -e 1,3d -e '$d' @@ -714,14 +714,14 @@ if inpath chronyc; then run_cached -s chrony 30 "waitmax 5 chronyc -n tracking | cat || true" fi -if inpath nvidia-settings && [ -S /tmp/.X11-unix/X0 ]; then +if inpath nvidia-settings && [[ -S /tmp/.X11-unix/X0 ]]; then echo '<<>>' for var in GPUErrors GPUCoreTemp; do DISPLAY=:0 waitmax 2 nvidia-settings -t -q $var | sed "s/^/$var: /" done fi -if [ -z "$IS_DOCKERIZED" ] && [ -z "$IS_LXC_CONTAINER" ] && [ -e /proc/drbd ]; then +if [[ -z "$IS_DOCKERIZED" ]]&&[[ -z "$IS_LXC_CONTAINER" ]]&&[[ -e /proc/drbd ]]; then echo '<<>>' cat /proc/drbd fi @@ -729,7 +729,7 @@ fi # Heartbeat monitoring # Different handling for heartbeat clusters with and without CRM # for the resource state -if [ -S /var/run/heartbeat/crm/cib_ro -o -S /var/run/crm/cib_ro ] || pgrep crmd > /dev/null 2>&1; then +if [[ -S /var/run/heartbeat/crm/cib_ro || -S /var/run/crm/cib_ro ]] || pgrep crmd > /dev/null 2>&1; then echo '<<>>' TZ=UTC crm_mon -1 -r | grep -v ^$ | sed 's/^ //; /^\sResource Group:/,$ s/^\s//; s/^\s/_/g' fi @@ -739,7 +739,7 @@ if inpath cl_status; then echo '<<>>' for NODE in $(cl_status listnodes); do - if [ "$NODE" != "$(echo "$HOSTNAME" | tr '[:upper:]' '[:lower:]')" ]; then + if [[ "$NODE" != "$(echo "$HOSTNAME" | tr '[:upper:]' '[:lower:]')" ]]; then STATUS=$(cl_status nodestatus "$NODE") echo -n "$NODE $STATUS" for LINK in $(cl_status listhblinks "$NODE" 2>/dev/null); do @@ -754,18 +754,18 @@ fi # Determine the number of mails and their size in several postfix mail queues read_postfix_queue_dirs() { postfix_queue_dir=$1 - if [ -n "$postfix_queue_dir" ]; then + if [[ -n "$postfix_queue_dir" ]]; then echo '<<>>' - if [ -n "$2" ]; then + if [[ -n "$2" ]]; then echo "[[[${2}]]]" fi for queue in deferred active; do count=$(find "${postfix_queue_dir}/$queue" -type f | wc -l) size=$(du -s "${postfix_queue_dir}/$queue" | awk '{print $1 }') - if [ -z "$size" ]; then + if [[ -z "$size" ]]; then size=0 fi - if [ -z "$count" ]; then + if [[ -z "$count" ]]; then echo "Mail queue is empty" else echo "QUEUE_${queue} $size $count" @@ -780,9 +780,9 @@ if inpath postconf; then # Check if multi_instance_directories exists in main.cf and is not empty # always takes the last entry, multiple entries possible multi_instances_dirs=$(postconf -c /etc/postfix 2>/dev/null | grep ^multi_instance_directories | sed 's/.*=[[:space:]]*//g') - if [ -n "$multi_instances_dirs" ]; then + if [[ -n "$multi_instances_dirs" ]]; then for queue_dir in $multi_instances_dirs; do - if [ -n "$queue_dir" ]; then + if [[ -n "$queue_dir" ]]; then postfix_queue_dir=$(postconf -c "$queue_dir" 2>/dev/null | grep ^queue_directory | sed 's/.*=[[:space:]]*//g') read_postfix_queue_dirs "$postfix_queue_dir" "$queue_dir" fi @@ -793,7 +793,7 @@ if inpath postconf; then read_postfix_queue_dirs "$postfix_queue_dir" fi -elif [ -x /usr/sbin/ssmtp ]; then +elif [[ -x /usr/sbin/ssmtp ]]; then echo '<<>>' mailq 2>&1 | sed 's/^[^:]*: \(.*\)/\1/' | tail -n 6 @@ -803,8 +803,8 @@ fi if inpath postfix; then echo "<<>>" for i in /var/spool/postfix*/; do - if [ -e "$i/pid/master.pid" ]; then - if [ -r "$i/pid/master.pid" ]; then + if [[ -e "$i/pid/master.pid" ]]; then + if [[ -r "$i/pid/master.pid" ]]; then postfix_pid=$(sed 's/ //g' < "$i/pid/master.pid") # handle possible spaces in output if readlink -- "/proc/${postfix_pid}/exe" | grep -q ".*postfix/\(s\?bin/\)\?master.*"; then echo "$i:the Postfix mail system is running:PID:$postfix_pid" | sed 's/\/var\/spool\///g' @@ -827,7 +827,7 @@ if inpath qmail-qstat; then fi # Nullmailer queue monitoring -if inpath nullmailer-send && [ -d /var/spool/nullmailer/queue ]; then +if inpath nullmailer-send && [[ -d /var/spool/nullmailer/queue ]]; then echo '<<>>' COUNT=$(find /var/spool/nullmailer/queue -type f | wc -l) SIZE=$(du -s /var/spool/nullmailer/queue | awk '{print $1 }') @@ -839,7 +839,7 @@ if inpath omd; then run_cached -s omd_status 60 "omd status --bare --auto || true" echo '<<>>' for statefile in /omd/sites/*/var/log/mknotifyd.state ; do - if [ -e "$statefile" ]; then + if [[ -e "$statefile" ]]; then site=${statefile%/var/log*} site=${site#/omd/sites/} echo "[$site]" @@ -849,7 +849,7 @@ if inpath omd; then echo '<<>>' for statsfile in /omd/sites/*/var/log/apache/stats; do - if [ -e "$statsfile" ]; then + if [[ -e "$statsfile" ]]; then site=${statsfile%/var/log*} site=${site#/omd/sites/} echo "[$site]" @@ -876,7 +876,7 @@ fi # Veritas Cluster Server # Software is always installed in /opt/VRTSvcs. # Secure mode must be off to allow root to execute commands -if [ -x /opt/VRTSvcs/bin/haclus ]; then +if [[ -x /opt/VRTSvcs/bin/haclus ]]; then echo "<<>>" vcshost=$(hostname | cut -d. -f1) waitmax -s 9 2 /opt/VRTSvcs/bin/haclus -display -localclus | grep -e ClusterName -e ClusState @@ -904,7 +904,7 @@ replace_datevariable() { fi } -if [ -r "$MK_CONFDIR/fileinfo.cfg" ]; then +if [[ -r "$MK_CONFDIR/fileinfo.cfg" ]]; then echo '<<>>' old_state=$(set +o) @@ -947,7 +947,7 @@ fi if cd /omd/sites; then echo '<<>>' for site in *; do - if [ -S "/omd/sites/$site/tmp/run/live" ]; then + if [[ -S "/omd/sites/$site/tmp/run/live" ]]; then echo "[$site]" echo -e "GET status" | \ waitmax 3 "/omd/sites/$site/bin/unixcat" "/omd/sites/$site/tmp/run/live" @@ -958,7 +958,7 @@ if cd /omd/sites; then for site in *; do echo "[$site]" for PEM_PATH in "/omd/sites/$site/etc/ssl/ca.pem" "/omd/sites/$site/etc/ssl/sites/$site.pem"; do - if [ -f "$PEM_PATH" ]; then + if [[ -f "$PEM_PATH" ]]; then CERT_DATE=$(openssl x509 -enddate -noout -in "$PEM_PATH") CERT_DATE=${CERT_DATE/notAfter=/} echo "$PEM_PATH|$(date --date="$CERT_DATE" --utc +%s)" @@ -968,7 +968,7 @@ if cd /omd/sites; then echo '<<>>' for site in *; do - if [ -S "/omd/sites/$site/tmp/run/mkeventd/status" ]; then + if [[ -S "/omd/sites/$site/tmp/run/mkeventd/status" ]]; then echo "[\"$site\"]" echo -e "GET status\nOutputFormat: json" \ | waitmax 3 "/omd/sites/$site/bin/unixcat" "/omd/sites/$site/tmp/run/mkeventd/status" @@ -986,7 +986,7 @@ if ls /omd/sites/*/var/check_mk/backup/*.state >/dev/null 2>&1; then JOB_IDENT=${F%.state} JOB_IDENT=${JOB_IDENT##*/} - if [ "$JOB_IDENT" != "restore" ]; then + if [[ "$JOB_IDENT" != "restore" ]]; then echo "[[[site:$SITE:$JOB_IDENT]]]" cat "$F" echo @@ -1001,7 +1001,7 @@ if inpath mkbackup && ls /var/lib/mkbackup/*.state >/dev/null 2>&1; then JOB_IDENT=${F%.state} JOB_IDENT=${JOB_IDENT##*/} - if [ "$JOB_IDENT" != "restore" ]; then + if [[ "$JOB_IDENT" != "restore" ]]; then echo "[[[system:$JOB_IDENT]]]" cat "$F" echo @@ -1016,8 +1016,8 @@ fi if pushd "$MK_VARDIR/job" >/dev/null; then echo '<<>>' for username in *; do - if [ -d "$username" ] && cd "$username"; then - if [ $EUID -eq 0 ]; then + if [[ -d "$username" ]] && cd "$username"; then + if [[ $EUID -eq 0 ]]; then su -s "$SHELL" "$username" -c "head -n -0 -v *" else head -n -0 -v ./* @@ -1030,11 +1030,11 @@ fi # Gather thermal information provided e.g. by acpi # At the moment only supporting thermal sensors -if [ -z "$IS_DOCKERIZED" ] && [ -z "$IS_LXC_CONTAINER" ] && ls /sys/class/thermal/thermal_zone* >/dev/null 2>&1; then +if [[ -z "$IS_DOCKERIZED" ]]&&[[ -z "$IS_LXC_CONTAINER" ]] && ls /sys/class/thermal/thermal_zone* >/dev/null 2>&1; then echo '<<>>' for F in /sys/class/thermal/thermal_zone*; do line="${F##*/}" - if [ ! -e "$F/mode" ]; then line="${line}|-" ; else line="${line}|$(cat "$F"/mode)"; fi + if [[ ! -e "$F/mode" ]]; then line="${line}|-" ; else line="${line}|$(cat "$F"/mode)"; fi line="${line}|$(cat "$F"/{type,temp} | tr \\n "|")" for G in $(ls "$F"/trip_point_*_{temp,type}); do line="${line}$(< "$G" tr \\n "|")" @@ -1064,7 +1064,7 @@ if inpath pvecm; then fi for HAPROXY_SOCK in /run/haproxy/admin.sock /var/lib/haproxy/stats; do - if [ -r "$HAPROXY_SOCK" ] && inpath socat; then + if [[ -r "$HAPROXY_SOCK" ]] && inpath socat; then echo "<<>>" echo "show stat" | socat - "UNIX-CONNECT:$HAPROXY_SOCK" fi @@ -1073,8 +1073,8 @@ done # Start new liveupdate process in background on each agent execution. Starting # a new live update process will terminate the old one automatically after # max. 1 sec. -if [ -e "$MK_CONFDIR/real_time_checks.cfg" ]; then - if [ -z "$REMOTE" ]; then +if [[ -e "$MK_CONFDIR/real_time_checks.cfg" ]]; then + if [[ -z "$REMOTE" ]]; then echo "ERROR: \$REMOTE not specified. Not starting Real-Time Checks." >&2 elif ! inpath openssl; then echo "ERROR: openssl command is missing. Not starting Real-Time Checks." >&2 @@ -1084,7 +1084,7 @@ if [ -e "$MK_CONFDIR/real_time_checks.cfg" ]; then fi # MK's Remote Plugin Executor -if [ -e "$MK_CONFDIR/mrpe.cfg" ]; then +if [[ -e "$MK_CONFDIR/mrpe.cfg" ]]; then grep -Ev '^[[:space:]]*($|#)' "$MK_CONFDIR/mrpe.cfg" | \ while read -r descr cmdline; do interval= @@ -1102,15 +1102,15 @@ if [ -e "$MK_CONFDIR/mrpe.cfg" ]; then key=$(echo "$par" | cut -d= -f1) value=$(echo "$par" | cut -d= -f2) - if [ "$key" = "interval" ]; then + if [[ "$key" = "interval" ]]; then interval=$value - elif [ "$key" = "appendage" ]; then + elif [[ "$key" = "appendage" ]]; then args="-ma" fi done fi - if [ -z "$interval" ]; then + if [[ -z "$interval" ]]; then run_mrpe "$descr" "$cmdline" else run_cached "$args" "$descr" "$interval" "$cmdline" @@ -1119,17 +1119,17 @@ if [ -e "$MK_CONFDIR/mrpe.cfg" ]; then fi # MK's runas Executor -if [ -e "$MK_CONFDIR/runas.cfg" ]; then +if [[ -e "$MK_CONFDIR/runas.cfg" ]]; then grep -Ev '^[[:space:]]*($|#)' "$MK_CONFDIR/runas.cfg" | \ while read -r type user include; do - if [ -d "$include" -o \( "$type" == "mrpe" -a -f "$include" \) ]; then + if [[ -d "$include" || ( "$type" == "mrpe" && -f "$include" ) ]]; then PREFIX="" - if [ "$user" != "-" ]; then + if [[ "$user" != "-" ]]; then PREFIX="su $user -c " fi # mrpe includes - if [ "$type" == "mrpe" ]; then + if [[ "$type" == "mrpe" ]]; then grep -Ev '^[[:space:]]*($|#)' "$include" | \ while read -r descr cmdline; do interval= @@ -1145,17 +1145,17 @@ if [ -e "$MK_CONFDIR/runas.cfg" ]; then for par in $(echo "$parameters" | tr ":" "\n"); do # split each assignment IFS='=' read -r key value <<< "${par}" - if [ "$key" = "interval" ]; then + if [[ "$key" = "interval" ]]; then interval=$value # no other parameters supported currently fi done fi - if [ -n "$PREFIX" ]; then + if [[ -n "$PREFIX" ]]; then cmdline="$PREFIX\'$cmdline\'" fi - if [ -z "$interval" ]; then + if [[ -z "$interval" ]]; then run_mrpe "$descr" "$cmdline" else run_cached -m "$descr" "$interval" "$cmdline" @@ -1163,14 +1163,14 @@ if [ -e "$MK_CONFDIR/runas.cfg" ]; then done # local and plugin includes - elif [ "$type" == "local" -o "$type" == "plugin" ]; then - if [ "$type" == "local" ]; then + elif [[ "$type" == "local" || "$type" == "plugin" ]]; then + if [[ "$type" == "local" ]]; then echo "<<>>" fi find "$include" -executable -type f | \ while read -r filename; do - if [ -n "$PREFIX" ]; then + if [[ -n "$PREFIX" ]]; then cmdline="$PREFIX\"$filename\"" else cmdline=$filename @@ -1224,7 +1224,7 @@ if cd "$PLUGINSDIR"; then fi # Agent output snippets created by cronjobs, etc. -if [ -d "$SPOOLDIR" ]; then +if [[ -d "$SPOOLDIR" ]]; then pushd "$SPOOLDIR" > /dev/null now=$(date +%s) @@ -1244,9 +1244,9 @@ if [ -d "$SPOOLDIR" ]; then done # If there is at least one digit, than we honor that. - if [ "$maxage" ]; then + if [[ "$maxage" ]]; then mtime=$(stat -c %Y "$file") - if [ $((now - mtime)) -gt "$maxage" ]; then + if [[ $((now - mtime)) -gt "$maxage" ]]; then continue fi fi