Link to home
Start Free TrialLog in
Avatar of jaysilverheels
jaysilverheels

asked on

script to add new line to file in multiple servers with ssh

This script below only works if there is one hostname in the hosts field at the start. Not sure if the appending is the best way either. Also have to sudo to root
#!/usr/bin/ksh
ADD="goodbye"
file="/tmp/bucket"
hosts="host1-1,host-2"

for i in ${hosts}  do
ssh ${i} ; sudo su -
"echo $ADD >> $file"
 done
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jaysilverheels
jaysilverheels

ASKER

only problem here is that with -s on sudo you need a password but how do you get around the ttyin /out?
Are you able to change the sudo setup on the remote servers?

If not, then your script will need to be more complicated.