It happens from time to time I want to execute a command on all cluster nodes and couldn't find a suitable method from the built-in tools. So I wrote this little shell script that I saved as /usr/bin/cssh and chmod +x'ed, and I thought it might come in handy for others.
Multiple commands seem to work fine when quotation is right, e.g.
The first time you use it it may ask for ssh-key authentication. Passwords shouldn't be problem but if so ssh-copy-id might help.
I've done some shell scripting but I'm no expert. Improvement are more than welcome.
<irony>Of course I take all responsibility when your whole cluster goes bye-bye because you ran a weird command
</irony>
Code:
#!/bin/bash
if [ -n "$1" ]; then
cmd="$@"
echo Executing \"$@\" on all cluster nodes
for n in `sed '/NAME/!d;s/ NAME: //' /etc/pve/cluster.cfg`; do
echo ---------------------------- $n ----------------------------
ssh -t -n $n $@
done
else
echo "Usage: $0 [command]"
fi
Code:
pvesh "apt-get update && apt-get -y dist-upgrade"
I've done some shell scripting but I'm no expert. Improvement are more than welcome.
<irony>Of course I take all responsibility when your whole cluster goes bye-bye because you ran a weird command

Last edited: