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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use expect and send command in UNIX/Linux?
# 1  
Old 03-04-2015
How to use expect and send command in UNIX/Linux?

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

Last edited by Scrutinizer; 03-04-2015 at 08:33 AM.. Reason: code tags
# 2  
Old 03-04-2015
I have never seen someone try to run expect in this fashion and combine shell script. You should do everything in one expect script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

To send ID and Password for each command using expect feature in bash script

Dear Tech Guys, I am trying to send some commands on the local server and it always asks for user name and password after each command. To serve the purpose I am using expect function as follows: #!/usr/bin/expect set timeout 20 spawn "./data1.sh" expect "Please Enter UserName: "... (6 Replies)
Discussion started by: Xtreme
6 Replies

2. Shell Programming and Scripting

Expect command to send the user input enter or ctrl+c

Hey All, I am writing one script using expect, that script which is used in spawn will accepts only 1. Enter 2. Ctrl+c Press Control-C to exit, Enter to proceed. Could some one share some thoughts to send the above user inputs in linux expect block ? Thanks, Sam (0 Replies)
Discussion started by: SCHITIMA
0 Replies

3. Shell Programming and Scripting

Expect - assigning UNIX command output to a variable

Hi, I'm writing a script that connects through ssh (using "expect") and then is supposed to find whether a process on that remote machine is running or not. Here's my code (user, host and password are obviously replaced with real values in actual script): #!/usr/bin/expect set timeout 1... (3 Replies)
Discussion started by: oseri
3 Replies

4. Shell Programming and Scripting

Expect/Send

Hello Team, Am trying to write a script for installing PAM in mulitiple server by using expect and send command. Am facing the below issues,could you please assist. thanks. # cat /tmp/gkscrpt.exp #!/usr/bin/expect -d spawn /tmp/agent/install_pam.sh expect -re "(y/n) " send --... (1 Reply)
Discussion started by: gowthamakanthan
1 Replies

5. Shell Programming and Scripting

problem in automating "fdisk" command using send and expect

hi i want to automate fdisk command . i spawned a process containing fdisk command from a process and tried to send the options to fdisk promt from that process. but that spawed process is notstarting itself help me out trying for two days :wall: my code: #!/bin/bash echo... (5 Replies)
Discussion started by: jagak89
5 Replies

6. Shell Programming and Scripting

no command is not working to send a mail in linux redhot server

HI All, I am facing the problem with rmail ... Actually my server is linux environment Redhot server. To send a mail which command I have to use it . I want subject and I want to Include CC also And body of the mail also there . But If I use rmail command it is not taking any options to... (1 Reply)
Discussion started by: ksrivani
1 Replies

7. Shell Programming and Scripting

Command substitution in send/expect. Please help!

Hi, the following code is not working. How can I cat the last modified file in the path /asdf. Please help! expect "asdf%" {send "cat `ls -rt /asdf|tail -1` \r"} (2 Replies)
Discussion started by: thulasidharan2k
2 Replies

8. Shell Programming and Scripting

Expect command on Linux

Hello All, can anyone let me know i can i execute scripts using expect on remote hosts. Regards Ankit (2 Replies)
Discussion started by: ajaincv
2 Replies

9. Shell Programming and Scripting

Is there a way to ask expect wait for sometime before running the next send command ?

Hi all, After expect catches the string I specify, is there a way to ask expect wait for sometime before running the next send command ? So my script looks like following, expect "some string" #How to ask expect to wait for a while send "next command" The reason I want to do this is... (0 Replies)
Discussion started by: qiulang
0 Replies

10. Shell Programming and Scripting

Use Send command of Expect package

HI All, I am currently working on one command line application on AIX (Unix Platform).Here i need to use Expect package. By using Expect package at the top of the script,i want to use just Send command of Expect package to send characters like, 1. Press Enter key 2. Press spacebar 3.... (6 Replies)
Discussion started by: neha123
6 Replies
Login or Register to Ask a Question