Find the answer to your Linux question:
Results 1 to 2 of 2
i have a shell file that's supposed to download a text file from an ftp server and copy it to the mysql server. this file is run from a cron ...
  1. #1
    Just Joined!
    Join Date
    Jun 2004
    Location
    NYC Metro Area
    Posts
    8

    ssh bash help

    i have a shell file that's supposed to download a text file from an ftp server and copy it to the mysql server.

    this file is run from a cron job.

    Code:
    #!/bin/sh
    
    # Set up FTP variables
    FTP_SERVER='google.com';
    FTP_USER='me';
    FTP_PASS='pass';
    FTP_DIR='dir';
    
    # Initialize variables
    MONTH=`date +'%m'`;
    DAY=`date +'%d'`;
    YEAR=`date +'%Y'`;
    
    # Set up file name variable
    REMOTE_FILE=$YEAR$MONTH$DAY"*.TXT";
    LOCAL_FOLDER='bnt_dump';
    
    # Define Url to get the regular dump
    URL="ftp://"$FTP_USER":"$FTP_PASS"@"$FTP_SERVER"/"$FTP_DIR"/"$REMOTE_FILE;
    
    # Transfer the file via ftp
    wget --tries=20 $URL --directory-prefix=$LOCAL_FOLDER -q;
    
    # MySQL
    
    # Login & Load the correct database
    mysql myDBname -u root -ppassword -h google.com;
    
    # Run the SQL statement
    TRUNCATE TABLE bnt;
    LOAD DATA LOCAL INFILE "/home/myUser/bnt_dump/bnt_dump/"$REMOTE_FILE".TXT" INTO TABLE bnt FIELDS TERMINATED BY ',';
    I have a few problems:

    1) When i run sh <name of file>.sh, the system downloads the file via FTP and logins in mySQL after that. However, it just stops after logging into mysql. it doesn't run the truncate or the load data statements.
    2) Also, all i know about the file name that i'm d/ling from the ftp server is that it starts with YYYYMMDD and ends with .TXT. I don't know what the middle part is (it's the timestamp), but I know that I'm only going to be downloading one file. How do I get the name of the file I just downloaded?

    Thanks a lot. Appreciate it.

  2. #2
    Just Joined!
    Join Date
    Jan 2007
    Posts
    90
    1 .MYSQL is a mysql shell and he commands in a shell script gets executed only if the previous command has exited.
    You can consult some mysql scripting to find out how to pass the input to mysql in one single line (something like MYSQL < " commands " ) ?

    2. ls -rt | tail -1
    there can be multiple ways but depends on how you want to work around.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...