Need help using expect in shell scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help using expect in shell scripts
# 1  
Old 09-19-2010
Need help using expect in shell scripts

hi all,

i have this script that accepts passwords automatically and its working in one host only. my problem is how will i use it if i need it to run in more than one host/server let say by using "for loop statement"

working :
Code:
  spawn bundle linux -r hostname checkpath /opt/home/support/.k5login
  expect "password:"
  send "xxxxyyyy0f!\r"
  interact

not working:
Code:
!/usr/bin/expect -f
for i in `awk '{print $1}' server_list`
do
     echo $i
     spawn bundle linux -r $i checkpath /opt/home/support/.k5login
     expect "password:"
     send "xxxyyyy!\r"
     interact
done

here is an error:

----
[root@kickstart SE]# ./ray1.sh
can't read "1": no such variable
while executing
"for i in `awk '{print$1}' server_list`"
(file "./ray1.sh" line 2)
-----

appreciate much your reply on this.

Last edited by linuxgeek; 09-20-2010 at 12:06 AM..
# 2  
Old 09-20-2010
please confirm that the first line reads
Code:
#!/usr/bin/expect -f

actually - I just re-read your code. You cannot embed shell script constructs in an expect script. You must use TCL constructs.
# 3  
Old 09-20-2010
ah i see... thanks frank, i will check then the TCL construct.

tnx tnx!

---------- Post updated at 02:55 PM ---------- Previous update was at 11:50 AM ----------

i need extended help for the equivalent of the ff statement:

for i in `awk '{print $1}' server_list` or

server_list=`cat $1`
for i in server_list
do
blah blah
....
done

how will i do this in TCL ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scripts triggered via 'expect' - stderr lost

I have a bash script on server that runs fine when run interactively and writes stderr output to a file. However, when invoked through a 'expect' script run on Mac OS my laptop which does ssh to the server : generates the expected file, but file has no content. I suspect the stderr is getting... (1 Reply)
Discussion started by: sdudc
1 Replies

2. Shell Programming and Scripting

Using Expect scripts to port files to different unix box

Hello all, I've been trying to design a script which will help me transfer files from one unix box to another. Following is the code: #!/usr/local/bin/expect spawn /usr/bin/scp ms_cp5_daily.ksh userid@cat:/prod/env/ms.txt set pass xxxxxx expect { password: {send "$pass\r";... (4 Replies)
Discussion started by: sethmj
4 Replies

3. Shell Programming and Scripting

How to use expect in shell script?

Dear friends, Could you please help me in writing a sample code to connect the remote system (through ssh) using expect in shell script. Thanks in advance.. :-) (1 Reply)
Discussion started by: rajesh.tulluri
1 Replies

4. Shell Programming and Scripting

Help with Expect in Shell Script

Hi All, I have a expect script which is working for single server, but if i am trying to pass value of the variable inside expect, it is not working. Please see below :- expect -c 'spawn ssh username@ip_address ; expect assword ; send "Password1\n" ; send "uptime \n" ; send "free -m \n" ;... (0 Replies)
Discussion started by: Renjesh
0 Replies

5. UNIX for Dummies Questions & Answers

Difference between using Here document and Expect in scripts

Hi, I am confused between using here document and using expect for writing interactive shell scripts(like changing password ,FTP or doing su). My questions are : 1)Why here documents cant change password from shell script. 2)Why we need to use expect for same? 3) Can Sourcing a script can do... (2 Replies)
Discussion started by: kailash19
2 Replies

6. Shell Programming and Scripting

How to handle scripts that expect an input

Hi I would like to know how to handle my script that expects an input when calling the script and the user doesn't enter anything, I need to re-direct to my helpfile. Bascically here is my script: #!/bin/bash csvdir="/var/local/dsx/csv/general" csvfile="$csvdir/$csvfile"... (3 Replies)
Discussion started by: ladyAnne
3 Replies

7. Shell Programming and Scripting

calling 'n' number of shell scripts based on dependency in one shell script.

Hello gurus, I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script. i m looking for something like this call 3.1; If 3.1 = "complete" then call 3.2; if 3.2 = ''COMPlete" then call 3.3; else exit The... (1 Reply)
Discussion started by: shashi369
1 Replies

8. Shell Programming and Scripting

Need help with Expect and Shell script

This is my shell script which calls an expect file, i am trying to find out server.log file sizes on various servers. But what should be correct way to do that, is there any way i can run a for loop inside the expect file which can take cat <filename> as input. I know for can be used in expect file... (1 Reply)
Discussion started by: tonan
1 Replies

9. Shell Programming and Scripting

Calling expect scripts from other expect scripts

Hi, First, let me explain the issue I am trying to solve. We have a lot of expect scripts with the duplicated send/expect commands. So, I'd like to be able to extract the duplicated code into the common scripts that can be used by other scripts. Below is my test where I am trying to call... (0 Replies)
Discussion started by: seva
0 Replies

10. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies
Login or Register to Ask a Question