I use:
iwashere() {
sleep $(shuf -i 1-9 | head -1)
date
echo "===> $(hostname) <===" > ~/I_WAS_HERE
}
env_parallel -Sserver-0{1..5} --tag --nonall iwashere
I like that I can try out the function locally before running it remotely.I like that I do not have to give xargs a multiline argument.
I am terrible at quoting inside quoting inside quoting, so I like that I can simply avoid the quoting. I also think my colleagues will find it easier to read (thus maintain).
xargs -t -n 1 -P 3 -I TARGET_COMPUTER ssh -q TARGET_COMPUTER "
sleep \$(shuf -i 1-9 | head -1)
echo \$(hostname; date)
echo \"===> \$(hostname) <===\"
> ~/I_WAS_HERE
" <<< "
server-01
server-02
server-03
server-04
server-05 "