how to read line inside expect script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to read line inside expect script
# 1  
Old 09-02-2010
how to read line inside expect script

hi,

i have an existing ftp script that needs to be translated to SFTP so i have to use expect script to automate the login to the remote server.

Now im facing with a problem becaise i have at least 50 files to be renamed ont he remote server. It's a hassle to hardcode every single command inside the expect script and because the filename is also changing according to date. So im thinking of putting the commands in a singel file name which will be read by teh expect script.

The file will look like:

Code:
rename file1 file1_date
rename file2 file2_date
.
.
rename file50 file50_date

I know this can be easily done with shel using the while read LINE command but not sure how to do this inside expect script.

Is is possible to do it in expect or they have a similar WHILE command in expect. If they have, really appreciate your help.
# 2  
Old 09-02-2010
Quote:
Originally Posted by The One
hi,

i have an existing ftp script that needs to be translated to SFTP so i have to use expect script to automate the login to the remote server.
You don't need expect to automate the login anymore(which is fortunate, since that's a very poor security practice.) ssh/scp/sftp (all the same protocol, ultimately) let you use a pre-shared key instead, much simpler, easier, more secure, and less bug-prone.

Quote:
Now I'm facing with a problem becaise i have at least 50 files to be renamed on the remote server. It's a hassle to hardcode every single command inside the expect script and because the filename is also changing according to date.
If sftp is available, ssh may also be available, which would let you run a full-fledged shell script on the remote host. You could do:

Code:
ssh user@host /bin/ksh < myscript.sh
# ...or bash or csh or whatever your shell of choice.

..and therein feed the local script 'myscript.sh' into the remote host and execute it there. If shared keys are set up, this will happen without a password -- all is needed are the right keyfiles in the right places.

Otherwise, you could do something like:
Code:
sftp user@host <<EOF > files
cd $DIR
ls
EOF

process_files_however_I_please < files > command_list

sftp user@host < command_list
rm -f command_list files


Last edited by Corona688; 09-02-2010 at 01:20 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

2. Shell Programming and Scripting

How to merge Expect script inside shell script?

Hi I have two scripts one is Expect and other is shell. I want to merge Expect code in to Shell script so that i can run it using only one script. Can somebody help me out ? Order to execute: Run Expect_install.sh first and then when installation completes run runTests.sh shell script. ... (1 Reply)
Discussion started by: ashish_neekhra
1 Replies

3. Shell Programming and Scripting

Expect not working inside my Bash script

I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows: #!/bin/bash HOST=$1 /usr/bin/expect -c " spawn ssh -i /root/.ssh/id_rsa root@$HOST expect -exact "Enter... (3 Replies)
Discussion started by: John Wilson
3 Replies

4. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

5. Shell Programming and Scripting

Expect script to read file line by line

I have an expect script which is run inside a bash script. I am trying to ssh to a jump server then from the jump server telnet to each router in a file list and run the same command. I tried many ways but down not read the router list file for some reason. I get the following error: wrong #... (0 Replies)
Discussion started by: numele
0 Replies

6. Shell Programming and Scripting

expect script inside shell script not working.

Shell Scipt: temp.sh su - <$username> expect pass.exp Expect script: pass.exp #!/usr/bin/expect -f # Login ####################### expect "Password: " send "<$password>\r" it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Discussion started by: bhavesh.sapra
2 Replies

7. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

8. Shell Programming and Scripting

Passing username and password to a script running inside "expect" script

Hi I'm trying to run a script " abc.sh" which triggers "use.sh" . abc.sh is nothing but a "expect" script which provides username and password automatically to the use.sh script. Please find below the scripts: #abc.sh #!/usr/bin/expect -f exec /root/use.sh expect "*name*" send... (1 Reply)
Discussion started by: baddykam
1 Replies

9. Shell Programming and Scripting

Can i use if else inside expect command in shell script?

hii,, I am trying to automate jira. during my scripting using bash script, in the terminal i got the terminal message like this: "Configure which ports JIRA will use. JIRA requires two TCP ports that are not being used by any other applications on this machine. The HTTP port is where you... (1 Reply)
Discussion started by: nithinfluent
1 Replies

10. Shell Programming and Scripting

how to run shell script inside expect script?

I have the code like this : shell script continues ... .... expect -c" spawn telnet $ip expect "login:" send \"$usrname\r\" expect "Password:" send \"$passwd\r\" expect "*\>" send \"$cmdstr\r\" ... (1 Reply)
Discussion started by: robbiezr
1 Replies
Login or Register to Ask a Question