Quantcast
Channel: Automatically Run Multiple Command over SSH on multiple devices - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 2

Automatically Run Multiple Command over SSH on multiple devices

0
0

I have 100+ devices that has same username and password and enabled SSH.

What I would like to achieve is for each device I want to run same command to change their password bulk.

What I did is to create 2 files; first one contains hosts, second one contains commands.

Hosts file example;

192.168.1.20
192.168.1.21
192.168.2.30
192.168.2.31

Commands file;

passwd -a des
%new-password%
%new-password%
grep -v users.1.password= /tmp/system.cfg > /tmp/system.cfg.new
echo users.1.password=`grep %user% /etc/passwd | awk -F: '{print $2}'` >> /tmp/system.cfg.new
cfgmtd -f /tmp/system.cfg.new -w
exit

I tried following command but its failing because of 2 reasons;

1 - It asks me to allow self-signed key everyime. 2 - It does stuck on input part

for host in $(cat hosts.txt); do ssh -u username@"$host" -pPasswd command.txt >"output.$host"; done

So basically I want to connect all device (they all have different self signed certificate) and change their password accordingly.

Thanks!


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images