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
MQdb::Database(3pm)					User Contributed Perl Documentation				       MQdb::Database(3pm)

NAME - MQdb::Database
DESCRIPTION
Generalized handle on an DBI database handle. Used to provide an instance which holds connection information and allows a higher level get_connection/ disconnect logic that persists above the specific DBI connections. Also provides a real object for use with the rest of the toolkit. SUMMARY
MQdb::Database provides the foundation of the MappedQuery system. Databases are primarily specified with a URL format. The URL format includes specification of a driver so this single method can select among the supported DBD drivers. Currently the system supports MYSQL, Oracle, and SQLite. The URL also allows the system to provide the foundation for doing federation of persisted objects. Each DBObject contains a pointer to the Database instance where it is stored. With the database URL and internal database ID, each object is defined in a global space. Attributes of MQdb::Database driver : mysql, oracle, sqlite (default mysql) user : username if the database requires password : password if the database requires host : hostname of the database server machine port : IP port of the database if required (mysql default is 3306) dbname : database/schema name on the database server for sqlite, this is the database file Example URLS mysql://<user>:<pass>@<host>:<port>/<database_name> mysql://<host>:<port>/<database_name> mysql://<user>@<host>:<port>/<database_name> mysql://<host>/<database_name> oracle://<user>:<pass>@/<database_name> oracle://<user>:<pass>@<host>:<port>/<database_name> sqlite:///<database_file> CONTACT
Jessica Severin <jessica.severin@gmail.com> LICENSE
* Software License Agreement (BSD License) * MappedQueryDB [MQdb] toolkit * copyright (c) 2006-2009 Jessica Severin * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Jessica Severin nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ new Description: instance creation method Parameter : a hash reference of options same as attribute methods Returntype : instance of this Class (subclass) Exceptions : none new Description: instance creation method Returntype : instance of this Class (subclass) Exceptions : none init Description: initialization method which subclasses can extend Returntype : $self Exceptions : subclass dependent new_from_url Description: primary instance creation method Parameter : a string in URL format Returntype : instance of MQdb::Database Examples : my $db = MQdb::Database->new_from_url("mysql://<user>:<pass>@<host>:<port>/<database_name>"); e.g. mysql://<host>:<port>/<database_name> e.g. mysql://<user>@<host>:<port>/<database_name> e.g. mysql://<host>/<database_name> e.g. sqlite:///<database_file> my $class = shift; Exceptions : none copy Description: makes a copy of the database configuration. New instance will have its own database connection Returntype : instance of MQdb::Database dbc Description: connects to database and returns a DBI connection Returntype : DBI database handle Exceptions : none disconnect Description: disconnects handle from database, but retains object and all information so that it can be reconnected again at a later time. Returntype : none Exceptions : none full_url Description: returns the URL of this database with user and password Returntype : string Exceptions : none url Description: returns URL of this database but without user:password used for global referencing and federation systems Returntype : string Exceptions : none xml Description: returns XML of this database but without user:password used for global referencing and federation systems Returntype : string Exceptions : none execute_sql Description : executes SQL statement with external parameters and placeholders Example : $db->execute_sql("insert into table1(id, value) values(?,?)", $id, $value); Parameter[1] : sql statement string Parameter[2..] : optional parameters for the SQL statement Returntype : none Exceptions : none do_sql Description : executes SQL statement with "do" and no external parameters Example : $db->do_sql("insert into table1(id, value) values(null,'hello world');"); Parameter : sql statement string with no external parameters Returntype : none Exceptions : none fetch_col_value Arg(1) : $sql (string of SQL statement with place holders) Arg (2...) : optional parameters to map to the placehodlers within the SQL Example : $value = $self->fetch_col_value($db, "select some_column from my_table where id=?", $id); Description: General purpose function to allow fetching of a single column from a single row. Returntype : scalar value Exceptions : none Caller : within subclasses to easy development perl v5.10.0 2009-05-30 MQdb::Database(3pm)
All times are GMT -4. The time now is 07:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy