1) Install expect tool in source machine

2) Create a file linux_name.exp and paste the below contents

#!/usr/bin/expect --
set loginName john
set yourPasswd zxasqw
spawn ssh $loginName@[lindex $argv 0]
expect Password
send $yourPasswd\r
expect $
send "sudo su -\r"
expect password
send $yourPasswd\r
expect #
send "uname -a\r"
send exit\r
expect close
exit 0
$

 

3) Create a file linux_name.sh and paste the below contents

#!/usr/bin/ksh
for i in `cat server_list`
do
echo "`expect /home/john/linux_name.exp $i`"
done