Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 09-17-2014, 11:31 AM   #31
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,713

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279

The return is embedded in the name (as shown by the "MF_BAT_BB160914192302.csv.PGP^M"), thus the "$i", includes a return.

I suggest changing the awk command from

awk '/MF_BAT/ {sub(/%$/,"",$0); print $0}' $FTPLIST
Old 09-26-2014, 03:04 PM   #32
Gary Patterson
LQ Newbie
Registered: Sep 2014
Posts: 1

Rep: Reputation: Disabled
This script does an mget, grabs the names of each file as it is fetched,and renames all of the files at the end.

set timeout 600
spawn sftp user@site
expect {
default {exit 2}
"password:" {send "password\n"; exp_continue}
send "cd myfolder\n"
expect {
default {exit 2}
send "progress\n"
expect {
default {exit 2}
set match ""
set file  ""
set files ""
set newfile ""
send "mget *out.done\n"
expect {
  "Fetching*to*\n" {
       regexp {/.*?\.out\.done} $expect_out(buffer) match
       append files $match\n
##     puts "\n---Files:\n$files\nMatch:\n$match"
  "sftp> " {puts "\n---Files:\n$files"}
  timeout {puts "Timeout"}
foreach file $files {
## puts "\n---Buffer:\n<$expect_out(buffer)>"
   set newfile [string map {.out.done .out.old} $file]
   send "rename $file $newfile\n"
   expect "sftp> "
send "quit\n"
exit 0


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
Issues with expect sftp manjuhp Linux - General 4 01-02-2014 03:09 PM
sftp group file rename solar05 Linux - Newbie 2 07-17-2009 01:10 AM
Running sftp under Expect and transfers fail jimbo1954 Linux - Software 2 11-27-2008 04:07 AM
Check for Success of SFTP transfer using expect kasthana Programming 4 06-03-2008 11:55 AM
transfer file using expect and sftp tanveer Linux - General 7 05-16-2008 11:29 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:00 AM.

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