FTP script to get latest file from server


 
Thread Tools Search this Thread
Operating Systems Linux Ubuntu FTP script to get latest file from server
# 8  
Old 11-24-2015
I was pointing out that your posts' specs are not consistent. What are the extensions? What are the file names ending on?

Try (untested)
Code:
ftp host <<< get .../TEKNONET/60468/0000060468$(date -d-1day +%Y%m%d)N001.CDR

# 9  
Old 11-24-2015
Inside remote dir... /TEKNONET/60468/ there are all .Zip files containing a CDR file. These zip files have the timestamp on them in the format 0000060468yyyymmddN001.Zip
# 10  
Old 11-24-2015
Are both machines in the same time zone.
Will there be a file on weekends and statutory holidays.
How much time is there between the time the file is available and the attempt to retrieve it.
Will a checksum be available.
# 11  
Old 11-24-2015
The time zone is the same.
The only thing is that in the remote dir the Zip file regarding every monday is not given, so whatever script you are going to write, it must have an option which tells that Monday's files must not be downloaded as they dont exists.
The scheduling of this script must be at least from 04.50 am to 08.30am you choose.
# 12  
Old 11-24-2015
Quote:
so whatever script you are going to write
It doesn't work quite like that. We help you write your script.
# 13  
Old 11-24-2015
Ok guys I managed to do all in this way and It is all working with a crontab schedule.

#!/bin/bash

START=`echo $1 | tr -d _`;
TABLE_NAME=M"`date --date="$START" +%Y%m%d`";

echo "Tabella del mese: "$TABLE_NAME;

if [ -f "/var/lib/mysql/database_name/"$TABLE_NAME".frm" ]
then echo "Tabella esistente: OK"

else
echo "Tabella non esistente, la creo";
SQL="create table "$TABLE_NAME"
(WHSSID int not null,
Seriale int not null,
DataOra datetime,
Chiamante text,
Chiamato text,
Prefisso_num_chiamato int,
Descr_prefisso_chiamato varchar(50),
Durata_secondi int,
Costo_conversazione text,
Chiamata_urb_extraurb int,
Chiamata_voce_dati int,
Chiamata_intratwt int,
Prefisso_carrier_destinazione int);";
echo $SQL > /tmp/sql;
mysql -D database_name -u database_name -p_database_password < /tmp/sql;
fi

FILE="ftp://ftp_user:ftp_pass@host/go/directory/0000060468$(date -d-0day +%Y%m%d)N001.Zip";
wget -qq $FILE -P /tmp;
unzip -qq -o -u /tmp/0000060468$(date -d-0day +%Y%m%d)N001.Zip -d /tmp;
SQL="load data local infile '/tmp/0000060468$(date -d-0day +%Y%m%d)N001.CDR' INTO TABLE $TABLE_NAME
FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'";
echo $SQL > /tmp/sql;
mysql -u database_name -pdatabase_password --local-infile database_name < /tmp/sql;
rm -rf /tmp/*

exit

Last edited by virtus96; 11-26-2015 at 04:26 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Upload latest file to ftp

Hi, I want to create a script that parses the content of a file (on each line there is a filename with full path containing the latest fiels created on that day) and uploads every file to a ftp location. Any elegant way to do it ? (4 Replies)
Discussion started by: liviusbr
4 Replies

2. Shell Programming and Scripting

Download latest file via ftp server unix through shell script

Hello this is my first post in this forum , I dont want to be unhappy.. I am writing one script but facing difficulty to find the latest file with some new pattern My requirement is 1. The file is coming like "ABCD-23220140303" at FTP server once in a week. 2. script will run on daily... (3 Replies)
Discussion started by: ajju
3 Replies

3. Shell Programming and Scripting

Script to upload latest file to other server via FTP

Hello, I have a script that finds the latest version of a file in a folder on my Minecraft server. I'm trying to come up with something that will then FTP that file over to my fileserver. Here's what I have that finds the newest file: find /home/mc/archive/sbhouse -type f -mtime +45 -exec... (7 Replies)
Discussion started by: nbsparks
7 Replies

4. Shell Programming and Scripting

How to FTP the latest file, based on date, from a remote server through a shell script?

How to FTP the latest file, based on date, from a remote server through a shell script? I have four files to be FTP'ed from remote server. They are of the following format. build1_runtime_mmddyyyy.txt build2_runtime_mmddyyyy.txt build3_runtime_mmddyyyy.txt buifile_count_mmddyyyy.txt ... (9 Replies)
Discussion started by: imran_affu
9 Replies

5. Shell Programming and Scripting

How to get latest file via FTP session

Hello , My requirement is as follows: I want to connect to a remote FTP server using FTP and then get the latest file from server location can u pls share code snippet for this ? Regards, Suresh (4 Replies)
Discussion started by: sureshg_sampat
4 Replies

6. Shell Programming and Scripting

Shell script for FTP a file from one server to another server

Hi Can any one help me for script. I need a script and this script has to execute daily to move the files. FTP from one server to another server EX: Sep 10 06:24 abc.txt Sep 11 06.56 abc.txt Sep 12 08.23 abc.txt these files are located at a/b/c/e/f in 123 server and copy... (0 Replies)
Discussion started by: mahantysk
0 Replies

7. UNIX for Dummies Questions & Answers

ftp command to get latest file

Hi, I would like an FTP command or series of commands to get only the latest file. Is that possible? Thanks in advance. (2 Replies)
Discussion started by: laiko
2 Replies

8. UNIX for Dummies Questions & Answers

Getting latest file from ftp

Hi, i have multile JAMA01.DAT.* files in my ftp. how can i get the latest file in from the ftp by executing the script :rolleyes:? Regards, Arun S (3 Replies)
Discussion started by: arunavlp
3 Replies

9. Shell Programming and Scripting

Shell script to ftp latest file

Hello All, Hope u r doing fine. I'm writing a shell script to ftp the latest file having pericular convention as 'ULTI_15072007043205.txt' on daily basis. Now the date & timing of the file geleration isnt constant, so the file name daily varies as per the date & timing of generation. Can anyone... (7 Replies)
Discussion started by: im_new
7 Replies

10. Shell Programming and Scripting

how to move a file from one server to another server using FTP in shell script?

I have a file --> file1.txt i need to copy this file to another server using FTP....the 2 servers are server1 and server2..may i know how to write a script that can do this? thanks in advance! Im a newbie to this... (4 Replies)
Discussion started by: forevercalz
4 Replies
Login or Register to Ask a Question