Sponsored Content
Operating Systems Linux Ubuntu FTP script to get latest file from server Post 302961135 by virtus96 on Tuesday 24th of November 2015 11:06:04 AM
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..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
MYSQL_LIST_FIELDS(3)							 1						      MYSQL_LIST_FIELDS(3)

mysql_list_fields - List MySQL table fields

SYNOPSIS
Warning This function was deprecated in PHP 5.4.0, and will be removed in the future, along with the entirety of the original MySQL exten- sion. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: oSQL Query: SHOW COLUMNS FROM sometable resource mysql_list_fields (string $database_name, string $table_name, [resource $link_identifier = NULL]) DESCRIPTION
Retrieves information about the given table name. This function is deprecated. It is preferable to use mysql_query(3) to issue an SQL SHOW COLUMNS FROM table [LIKE 'name'] statement instead. o $database_name - The name of the database that's being queried. o $table_name - The name of the table that's being queried. o $ link_identifier -The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect(3) is assumed. If no such link is found, it will try to create one as if mysql_connect(3) was called with no arguments. If no connection is found or established, an E_WARNING level error is generated. A result pointer resource on success, or FALSE on failure. The returned result can be used with mysql_field_flags(3), mysql_field_len(3), mysql_field_name(3) and mysql_field_type(3). Example #1 Alternate to deprecated mysql_list_fields(3) <?php $result = mysql_query("SHOW COLUMNS FROM sometable"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { print_r($row); } } ?> The above example will output something similar to: Array ( [Field] => id [Type] => int(7) [Null] => [Key] => PRI [Default] => [Extra] => auto_increment ) Array ( [Field] => email [Type] => varchar(100) [Null] => [Key] => [Default] => [Extra] => ) Note For backward compatibility, the following deprecated alias may be used: mysql_listfields(3) mysql_field_flags(3), mysql_info(3). PHP Documentation Group MYSQL_LIST_FIELDS(3)
All times are GMT -4. The time now is 12:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy