Link to home
Start Free TrialLog in
Avatar of fireburn11
fireburn11

asked on

Shell script needed to modify a file

Hi , I have a list of hosts with IP address and I need a script to ssh into each of the IPs,  add the following text into /etc/dhcpcd.conf file.


#Add to /etc/dhcpcd.conf
 
interface eth0 static ip_address=192.168.1.x/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1


can somehomw advise who to use for loop to do this? I don't have key pair so I am ok with typing in password for 30 times.

the list of IPs i have is from 192.168.1.1 to 192.168.1.30

Thank you!
Avatar of David Favor
David Favor
Flag of United States of America image

To write your script, likely better to hire someone to do this, so they can produce a solid script for you.

To resolve the password inputting problem is simple. You'll install the sshpass package on your Linux Distro, so on Debian/Ubuntu...

apt-get install sshpass

Open in new window


Then instead of a key pair, use a command like this...

sshpass -p $password ssh $user@$host -- /path-to-script-here 

Open in new window


Keep in mind, if you can login with a password, creating an empty phase phrase key pair is trivial, so better to do this, than use sshpass.
ASKER CERTIFIED SOLUTION
Avatar of Prabhin MP
Prabhin MP
Flag of India image

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