Cron Wrapper with Locking
Run a command from cron with a lock, timestamped log, and exit status.
$ webtoolist --script batch-command-runner
Run one command on a list of SSH hosts, sequentially, with clear output.
sshbatchautomationparallelDependencies: ssh
#!/usr/bin/env bash
set -euo pipefail
hosts_file="${1:-}"
shift || true
(($# > 0)) || { echo "usage: $0 HOSTS_FILE COMMAND [ARGS...]" >&2; exit 1; }
[[ -r "$hosts_file" ]] || { echo "cannot read $hosts_file" >&2; exit 1; }
command="$*"
fail=0
while IFS= read -r host; do
[[ -z "$host" || "$host" == \#* ]] && continue
echo "== $host =="
if ssh -o BatchMode=yes -o ConnectTimeout=5 "$host" "$command"; then
echo "-- ok"
else
echo "-- failed ($?)" >&2
fail=1
fi
done < "$hosts_file"
exit "$fail"
printf '%s\n' web1 web2 db1 > hosts.txt
./batch-command-runner hosts.txt 'uptime && df -h /'
BatchMode=yes fails instead of prompting for a password, which is what you want in automation.Related scripts
Run a command from cron with a lock, timestamped log, and exit status.
Summarise recent failed SSH logins by source address.
Inspect sshd configuration for common risky settings without changing anything.