Hi guys,
I recently managed to write up my working script, but now I have a problem.
If the file isn't there in the remote server, my actual script jumps it and all ok, but I need something like this:
Search file -> if there, then download -> if not, download next file in the list.
Any suggestions?
sea
November 28, 2015, 2:48am
2
How does your script look like?
Since you want us to help you imrpove it, we'd like to continue from what is there, and not reinvent the wheel.
But either way you could try:
list="file1 file2"
for this in $list;do
if [ -f "$this" ]
then echo "Downloading: $this"
else continue
fi
done
hth
#!/bin/bash
for i in {20151101..20151127}; do
mkdir -p /tmp/zip;
wget -qq ftp://ftp_user:ftp_pass@ftp.twt.it/TEKNONET/60468/0000060468"$i"N001.Zip -P /tmp/zip;
mkdir -p /tmp/cdr;
unzip -qq /tmp/zip/0000060468"$i"N001.Zip -d /tmp/cdr;
START=`echo $1 | tr -d _`;
TABLE_NAME=M"$i";
echo "Tabella del mese: "$TABLE_NAME;
if [ -f "/var/lib/mysql/twt/"$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 twt -u root -pp1ngu1n0 < /tmp/sql;
fi
SQL="load data local infile '/tmp/cdr/0000060468"$i"N001.CDR' INTO TABLE $TABLE_NAME
FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'";
echo $SQL > /tmp/sql;
mysql -u root -ppassword --local-infile twt < /tmp/sql;
rm -rf /tmp/*
done
RudiC
November 28, 2015, 8:43am
4
Please use code tags as required by forum rules
Not sure I understand your problem. Can't you wget
all thre relevant and existing files in one go and then only loop through the list to store them in the DB?
I did not understand the tag question.
Btw, how would you change my script in?
RudiC
November 28, 2015, 2:25pm
6
man wget
:
Retrieve all the target files by either specifying wildcard chars or using the --input-file
option to wget.
Then, loop through the files received loading them into your DB.
So something like that?
Do
Wget
Done
For x in ()
Do
Load data infile
Done
RudiC
November 29, 2015, 5:06am
8
Yes, sort of
prepare URLfile
wget --input-file URLfile
for FN in /path/to/*.zip
do
... whatever ...
done