I have this working:
% cat read.sh
!/bin/sh
file=list.txt
while read line
do
echo "$line"
cut -d' ' -f27 | sed -n '$p' > file2
done < "$file"
% cat list.txt
sftp> #!/bin/sh
sftp>
sftp> cd u/aaa
sftp> ls -lrt x_*.csv
-rwxr-xr-x 0 1001 1001 12274972 May 13 21:07 x_20150501.csv
-rw-r--r-- 0 1001 1001 0 May 13 21:44 x_20150601.csv
-rw-r--r-- 0 1001 1001 0 May 13 21:44 x_20150701.csv
-rw-r--r-- 0 1001 1001 0 May 13 21:44 x_20150801.csv
-rw-r--r-- 0 1001 1001 0 May 13 21:44 x_20150901.csv
-rw-r--r-- 0 1001 1001 0 May 13 21:45 x_20151001.csv
-rw-r--r-- 0 1001 1001 0 May 13 21:45 x_20151101.csv
-rw-r--r-- 0 1001 1001 0 May 13 21:45 x_20151201.csv
% cat file2
x_20151201.csv
First question: Is there something more glamorous to read just the very last item on the very last line? Would you use cut and sed? This is a redirect of a sftp directoy listing.
Second question: Whatever is in file2, I want to have it read from a sftp batch file to get that exact file.
% cat fetch.sh
#!/bin/sh
cd u/aaa
!sh read.sh
!< file2
get
bye
As you can imagine, sftp doesn't like get
provided without any file, so how can I read in file2 to get that file from the sftp server?
% sftp -b fetch.sh user@pulse
sftp> #!/bin/sh
sftp>
sftp> cd u/aaa
sftp> !sh read.sh
sftp> #!/bin/sh
sftp> !< file2
x_20151201.csv
sftp> get
You must specify at least one path after a get command.