Skip to content

Instantly share code, notes, and snippets.

@sparr
Created January 6, 2015 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sparr/bd0a3bc8915e0a3da0ee to your computer and use it in GitHub Desktop.
Save sparr/bd0a3bc8915e0a3da0ee to your computer and use it in GitHub Desktop.
run sudo command with privileged pipe output on multiple servers via ssh
for i in SERVER1 SERVER2 SERVER3
do
echo $i
ssh -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $i "echo PASSWORD | sudo -S sh -c 'echo LINE1 > /privileged/file' "
echo
ssh -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $i "echo PASSWORD | sudo -S sh -c 'echo LINE2 >> /privileged/file' "
echo
ssh -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $i "echo PASSWORD | sudo -S sh -c 'echo LINE3 >> /privileged/file' "
echo
echo done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment