Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save visitbethel/856381d65dbde5a5c6f3109b0bc50f8b to your computer and use it in GitHub Desktop.
Save visitbethel/856381d65dbde5a5c6f3109b0bc50f8b to your computer and use it in GitHub Desktop.
sledgehammer distributed command with sudo
dsh ls /etc/bashrc | perl -ne 'BEGIN { printf "export ss=\${1};shift;export args=\$@;" }{ $_=~s/://g;@x=split /\s+/;printf "ssh -t %s \"echo \${ss} | sudo -S -u tibcosilver \${args} \"\n",$x[0], $x[2]}' | tee out
perl -i -pe "s/#/'/g" out
echo "Please run: . out [Password]"
Will generate something like this:
ssh -t vangrant1.com "echo ${ss} | sudo -S -u appuser ${args} "
ssh -t vangrant2.com "echo ${ss} | sudo -S -u appuser ${args} "
Then can be used like this
$ . out [sshpassword] [anycommand]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment