LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-28-2014, 05:13 PM   #1
dotran
LQ Newbie
 
Registered: Apr 2012
Posts: 27
Blog Entries: 2

Rep: Reputation: Disabled
Help with expect script set timeout.


I wrote the bash script/expect code got connection and put files no issue. But problem need increase/decrease set timeout if run big/small file then job run. Anyone have experience with expect. Please help...I had been google all days and testing my different options still not work. Thanks

Quote:
#!/usr/bin/bash

WORK_DIR="$1"
FILENAME="$2"
LOGIN_ID="$3"
SERVER="$4"
REMOTE_DIR="$5"

/usr/local/bin/expect<<Do_EOD

set timeout 30
spawn sftp $LOGIN_ID@$SERVER
expect "assword:"
send "$KEY_PASSWORD\r"
expect sftp>
send "cd $REMOTE_DIR \r";
expect sftp>
send "pwd \r";
expect sftp>
send "mput $FILENAME \rls -l $FILENAME \r";
set timeout 1000
#set timeout 10000
#expect { "*100%*" { } timeout { exit 2 } }

expect sftp>
send "exit\r"
Do_EOD
 
Old 01-28-2014, 06:25 PM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636
For me it always "just worked".

Add this as first statement in the expect part:
Code:
exp_internal 1
It might shed some light on what is going on.

jlinkels
 
Old 01-28-2014, 06:28 PM   #3
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636
And if your only challenge is to put files through FTP on a remote site, have a look at ncftpput. Then you don't need expect at all. The difference is that sftp was designed to be interactive. If you want to use it in batch mode you need a workaround -- expect. Ncftpput was designed for batch operation. It suits your needs better.

jlinkels
 
Old 01-28-2014, 06:52 PM   #4
rigor
Member
 
Registered: Sep 2011
Posts: 218

Rep: Reputation: Disabled
If the problem is passing in a timeout, what I've included below worked for me. I did add a cd to the WORK_DIR and adjusted the paths for my system.

Code:
#!/bin/bash

WORK_DIR="$1"
FILENAME="$2"
LOGIN_ID="$3"
SERVER="$4"
REMOTE_DIR="$5"
TIME_OUT="$6"

cd ${WORK_DIR}

/usr/bin/expect<<Do_EOD

set timeout 30
spawn sftp $LOGIN_ID@$SERVER
expect "assword:"
send "$KEY_PASSWORD\r"
expect sftp>
send "cd $REMOTE_DIR \r";
expect sftp>
send "pwd \r";
expect sftp>
send "mput $FILENAME \rls -l $FILENAME \r";
set timeout $6
#set timeout 10000
#expect { "*100%*" { } timeout { exit 2 } }
expect sftp>
send "exit\r"
Do_EOD
If the problem you are having is something else, like getting the "timeout logic" to execute when the timeout period elapses, you can add a " -x" after bash on the first line of the file, and " -d" ( needs to be lower case ) after expect but before the << of the here document. Both of those together will give you some idea what bash and expect are "thinking" about your code.

HTH.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 10:06 PM
[root@fugo trace]# sh expect.sh expect.sh: line 9: expect: command not found sivaloga Linux - Kernel 1 08-22-2013 05:29 AM
Expect (TCL) freeze issue as timeout didnt get triggered vrs Programming 0 05-22-2013 11:44 PM
[SOLVED] Problem in exporting variable from bash script to expect script uk.engr Linux - Newbie 3 06-14-2012 02:57 AM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-28-2010 12:27 AM


All times are GMT -5. The time now is 08:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration