ssh, sudo, tty, shell

14 Jul 2011

A nice little script snippet I like to remember for automating quick stuff across multiple hosts. -t forces tty (so sudo will work); -q quiet – disable banners; -c script (“command”) to su. Presumes sudo doesn’t prompt for a password; otherwise, see Expect and Exploring Expect :-)

for h in $hosts ; do
  echo -e "nnhost: $hn------------------------------------"
  ssh -t -q $h "sudo su - -c "magic_stuff" "
comments powered by Disqus

  « Previous: Next: »