LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 09-17-2014, 11:31 AM   #31
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241

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

Code:
awk '/MF_BAT/' $FTPLIST
to
Code:
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.

Code:
#!/bin/expect
set timeout 600
spawn sftp user@site
expect {
default {exit 2}
"password:" {send "password\n"; exp_continue}
"sftp>"
}
send "cd myfolder\n"
expect {
default {exit 2}
"sftp>"
}
send "progress\n"
expect {
default {exit 2}
"sftp>"
}
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"
       exp_continue
    }
  "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
 
  


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
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


All times are GMT -5. The time now is 06:31 PM.

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