Personal tools
You are here: Home DB2 SSH passing password from script.
Log in

Forgot your password?
Document Actions

SSH passing password from script.

Sometimes you want to automate the execution of commands on each DB2 server you own from a computer where there is no db2 client installed. Here is a little trick showing you how to do it.

From Ubuntu:

sudo apt-get install expect

Create a script like this one: sshlogin.exp

#!/usr/bin/expect -f
set password [lrange $argv 0 0]
set ipaddr [lrange $argv 1 1]
set username [lrange $argv 2 2]
set command [lrange $argv 3 3]

set timeout -1

spawn ssh $username@$ipaddr $command
match_max 100000

expect "*?assword:*"
send -- "$password\r"
send -- "\r"
expect eof

Create your automation script:


arrServers=(db2srv1 db2srv2 db2srv3 db2srv4 db2srv5 db2srv6 db2srv7 db2srv8 db2srv9 db2srv10)


for server in ${arrServers[@]}
  echo $server
  echo "--------"
  ./sshlogin.exp $password $server $username $command
  echo " "

Then just run, it will show you the result of db2ls !

Security Awareness
Would you like your company to implement gamification into your security awareness program?