Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

How to use expect and send command in UNIX/Linux?

$
0
0
Hello Everyone,

I am executing a unix script which logs into 50+ servers (netapp servers) and runs some commands and captures output locally. Below is the code snippet. file1.txt has names of all the remote servers where I am logging in.

Code:

    #!/bin/ksh
    #!/usr/bin/expect
    touch ~/snapmirror_output.txt
    for i in `cat file1.txt`
    do
  /usr/bin/ssh username@$i snapmirror status > ~/snapmirror_status.txt; expect "password:" send "password\r";awk '{split($4,a,":"); if (a[1]>=24) print}' ~/snapmirror_status.txt >> ~/snapmirror_output.txt;rm -rf ~/snapmirror_status.txt
  done

All the remote servers have the same password for the user (username) which is used above. Although I am using expect and send commands in the script with the correct password but still the script is asking for password for each server when I am running the script. Please help. Thanks a lot.

Rahul

Viewing all articles
Browse latest Browse all 16232

Latest Images

Trending Articles



Latest Images