Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Having a bit of trouble trying to get an Expect script to do something simple!
I need to rename a file after I've downloaded it, and although I've probably gone the long way round I've got an 'almost' working solution.
I download the files, and then do an ls and pass the contents to a variable, then find the files within that variable and run through each line in a loop... the problem is with the rename command:
The problem is with send "rename $i PROCESSED_$i"...
If I substitute the $i for the actual filename in txt it works fine, but as soon as I add the $i it tries to send the command immediately after the first $i and therefore the SFTP Session just moans that the rename command is unfinished.
sftp> cd Output
sftp> rename MF_BAT_BB160914192302.csv.PGP
You must specify two paths after a rename command.
sftp> PROCESSED_MF_BAT_BB160914192302.csv.PGP
Invalid command.
sftp> bye
So it picks up the filename from the loop... and adds it to the rename command.. and also it constructs the new filename... but it separates the commands into two!
If anyone has any ideas, it would be greatly appreciated.
Thanks
Jon
Last edited by jonnybinthemix; 09-17-2014 at 05:43 AM.
Not sure what you mean by the file I'm reading in? There's a chance the file was created by a windows box, but I'm not calling in the file really, I'm just renaming it on the remote SFTP server.
spawn sftp -oPort=22 Login@XX.XX.XX.XX^M$
Connecting to XX.XX.XX.XX...^M$
reverse mapping checking getaddrinfo for xxxx-xxxx.xxxxxx.xxx-xx.com [XX.XX.XX.XX] ^M^M$
Login@XX.XX.XX.XX's password: ^M$
sftp> cd Output^M$
sftp> ls -1 *160914*^M$
MF_BAT_BB160914192302.csv.PGP^M$
sftp> bye^M$
just realised I changed the ls command.. it's sending ls -1 *$D*, $D is just $(date -d 'yesterday' +%d%m%y) so it's listing files with yesterdays date in the name.
spawn sftp -oPort=22 Login@XX.XX.XX.XX^M$
Connecting to XX.XX.XX.XX...^M$
reverse mapping checking getaddrinfo for xxxx-xxxx.xxxxxx.xxx-xx.com [XX.XX.XX.XX] ^M^M$
Login@XX.XX.XX.XX's password: ^M$
sftp> cd Output^M$
sftp> ls -1 *160914*^M$
MF_BAT_BB160914192302.csv.PGP^M$
sftp> bye^M$
just realised I changed the ls command.. it's sending ls -1 *$D*, $D is just $(date -d 'yesterday' +%d%m%y) so it's listing files with yesterdays date in the name.
those ^M's usually indicate windows newlines... it is the equivelent of hitting the return key after the filename (MF_BAT_BB160914192302.csv.PGP-enter-key).
seems like you are sending \r in the previous iteration.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.