Picking up last two specific files, for transfer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Picking up last two specific files, for transfer
# 1  
Old 06-26-2018
Picking up last two specific files, for transfer

Hi

I need to transfer files with csv extension from one server to another (all running solaris).
But the files to be picked are in a directory that also has:

Code:
/directory
deposit_698.csv
deposit_698.checksum
deposit_699.csv
deposit_699.checksum
deposit_700.csv
deposit_700.checksum
Withdrawal_697.csv
Withdrawal_697.checksum
Withdrawal_698.csv
Withdrawal_698.checksum
Withdrawal_699.csv
Withdrawal_699.checksum
Withdrawal_700.csv
Withdrawal_700.checksum

In this case I need to transfer the deposit_700.csv and the Withdrawal_700.csv to a deposits folder on another server and withdrawls folder.

My script is as follows:

Code:
#!/bin/sh
HOST=192.168.6.25
USER=rico
PASSWD=123xyz
/usr/bin/ftp -inv <<EOF
open $HOST
user $USER $PASSWD
binary
cd /home/scripts/Live deposits/input
mput *Deposit_* | head -n 1*
cd /home/script/Live withdrawal/input
mput *Withdrawal_* | head -n 1*
bye
EOF

My first problem is that one of the directory name in the destination server has a space on the directory name Live deposits and live withdrawals.
the second problem is that I am not able to transfer the last Deposit_700.csv and Withdrawal_700.csv.

my files are going to one folder before the folder with space on its name

---------- Post updated at 12:31 PM ---------- Previous update was at 12:04 PM ----------

Hi

I solve my first problem by using:

cd /home/scripts/Live\ deposits/input
# 2  
Old 06-26-2018
Is that always the same running number, i.e. 700 in above? Are the files created in that sequence, i.e. *700* are the newest? Do respective deposit_* and Withdrawal_* files have identical timestamps?
# 3  
Old 06-26-2018
No, everyday a new files are generated, so tomorrow will be Deposit_701.csv and Withdrawal_701, so every single day, there will be a new file
# 4  
Old 06-26-2018
You could remove the OPEN command by putting the hostname on the ftp line:-
Code:
/usr/bin/ftp -inv $ HOST <<EOF

The files you have are local (your client sends) so work them out before starting the FTP.

Would you not be better with tail?

Code:
#!/bin/sh

# Determine files first
D_file=$(ls -1 *Deposit_*" | tail -1)
W_file=$(ls -1 *Withdrawal_*" | tail -1)

# Call the FTP
HOST=192.168.6.25
USER=rico
PASSWD=123xyz
/usr/bin/ftp -inv $HOST <<EOF
user $USER $PASSWD
binary
cd /home/scripts/Live deposits/input
put "$D_file"
cd /home/script/Live withdrawal/input
put "$W_file"
bye
EOF

Does that help? If it doesn't work, please post your output/errors.



Kind regards,
Robin
# 5  
Old 06-26-2018
I did a test, outside the script of the following line:
Code:
 ls -1 *Withdrawal_*" | tail -1
>

what come out was >
# 6  
Old 06-26-2018
Quote:
Originally Posted by fretagi
I did a test, outside the script of the following line:
Code:
 ls -1 *Withdrawal_*" | tail -1
>

what come out was >
loose the "
# 7  
Old 06-26-2018
after your suggested changes, on the other server (destination) the output is strange:

Code:
ls -lrt
total 2
-rw-r--r--   1 rico  rico       32 Jun 26 15:33 |

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Picking up files conditionally

Hi I have a scenario: I have a directory say DIR1 (no sub directories) and have few files in that directory as given below: app-cnd-imp-20150820.txt app-cxyzm-imp-20150820.txt app-petco-imp-20150820.txt app-mobility-imp-20150820.txt app-mobility-imp-20150821.txt... (7 Replies)
Discussion started by: Saanvi1
7 Replies

2. Linux

How to transfer files...

Hi guys, ok so, how do you go about networking between Windows and Linux so that I can transfer files between each other? (5 Replies)
Discussion started by: billcrosby
5 Replies

3. UNIX for Dummies Questions & Answers

Sorting files based on timestamp and picking the latest file

Hi Friends, Newbie to shell scripting Currently i have used the below to sort data based on filenames and datestamp $ printf '%s\n' *.dat* | sort -t. -k3,4 filename_1.dat.20120430.Z filename_2.dat.20120430.Z filename_3.dat.20120430.Z filename_1.dat.20120501.Z filename_2.dat.20120501.Z... (12 Replies)
Discussion started by: robertbrown624
12 Replies

4. Shell Programming and Scripting

Urgent ...pls Sorting files based on timestamp and picking the latest file

Hi Friends, Newbie to shell scripting. Currently i have used the below to sort data based on filenames and datestamp $ printf '%s\n' *.dat* | sort -t. -k3,4 filename_1.dat.20120430.Z filename_2.dat.20120430.Z filename_3.dat.20120430.Z filename_1.dat.20120501.Z filename_2.dat.20120501.Z... (1 Reply)
Discussion started by: robertbrown624
1 Replies

5. Shell Programming and Scripting

Transfer Of Files

How to transfer the files in windows server to the unix server by using the unix or ftp commands? (1 Reply)
Discussion started by: vinay123
1 Replies

6. Shell Programming and Scripting

Copying specific files from remote m/c to specific folders

Hi All, I am trying to rsync some of the latest files from remote m/c to my local linux box. Folder structure in my remote m/c looks like this /pub/Nightly/Package/ROLL/WIN /pub/Nightly/Package/SOLL/sol /pub/Nightly/Package/SOLL/linux Each of the folder contains gzip files which on daily... (0 Replies)
Discussion started by: jhoomsharabi
0 Replies

7. UNIX for Dummies Questions & Answers

How to transfer files

please help me to transfer files from one server to another one i am having problem in it thanks (1 Reply)
Discussion started by: pankaj001np
1 Replies

8. UNIX for Dummies Questions & Answers

How to transfer files

(0 Replies)
Discussion started by: spoonman
0 Replies

9. Shell Programming and Scripting

transfer of specific file content to another file

What commands do you need to transfer a specfic portion of a file content to another file? eg file_one has 00012 10012 00013 10013 00014 10014 So I just want to transfer all the values of the second column ie 10012, 10013, 10014 to be transferred to file_two? Thanks in advance.... (1 Reply)
Discussion started by: mem101
1 Replies

10. UNIX for Advanced & Expert Users

How do i transfer files

Im trying to transfers a file from one unix server to another , make some changes and then send it back to the original server. All this using modems. I've been using "cu" and i can "get" the file but i can't "put" it. Besides I need to do this using a shell script. I can write a script to get... (4 Replies)
Discussion started by: phsoft
4 Replies
Login or Register to Ask a Question

Featured Tech Videos