LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-31-2007, 04:40 AM   #1
mistiqshannen
LQ Newbie
 
Registered: May 2007
Posts: 3

Rep: Reputation: 0
How to write a command to FTP files with dates filenames


I have this production server that FTP files to standby server.
I created a job (.sh file) that runs regularly to FTP those files
but the filenames has dates like for example
ITEM_MPN_DW_20070531112159.txt

my script goes like this:

#!/bin/bash
DATE=`date +%Y%m%d%H`

cd /home/wphfpdw/F021/history
ftp -v -n << "END"
open <IP>
user <user password>
bin
hash
prompt
cd /home/wphfpdw/F021/history
mput *.* #this should be change to get the files generated today.
bye
END

in this script i ftp all files. I need only to FTP files generated for
today. so that I wont keep transferring old files over and over again.
How can I write a command that uses DATE as variable so that i will just get
the files with for example ITEM_MPN_DW_<Today's date>112159.txt

thanks.. really need your help

naj
 
Old 05-31-2007, 04:48 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

You are halfway there already:

The DATE variable is set in your script but not used. Change it to DATE=`date +%Y%m%d` (remove the %H part).

Now you can change the *.* part into: *${DATE}*
This should target today's files.

Hope this helps.
 
Old 06-03-2007, 09:19 PM   #3
mistiqshannen
LQ Newbie
 
Registered: May 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by druuna
Hi,

You are halfway there already:

The DATE variable is set in your script but not used. Change it to DATE=`date +%Y%m%d` (remove the %H part).

Now you can change the *.* part into: *${DATE}*
This should target today's files.

Hope this helps.
hi, i tried to edit the script and it doesn't work. I just changed *.* part to *${DATE}*
and change the date to DATE=`date +%Y%m%d`.

it just execute and it doesn't FTP any file

thanks
 
Old 06-04-2007, 04:46 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

I just noticed that there are double quotes around the first END, the shouldn't be there. I.e:
Code:
#!/bin/bash
DATE="`date +%Y%m%d`"

cd /home/wphfpdw/F021/history
ftp -v -n <<END
open <IP>
user <user password>
bin
hash
prompt
cd /home/wphfpdw/F021/history
mput *${DATE}* 
bye
END
Hope this helps.
 
Old 06-05-2007, 01:13 AM   #5
mistiqshannen
LQ Newbie
 
Registered: May 2007
Posts: 3

Original Poster
Rep: Reputation: 0
its really no double quotation marks. this is the script goes..
but it doesnt work..

#!/bin/bash

DATE=`date +%Y%m%d`
cd /home/wphfpdw/F021/history
ftp -v -n << "END"
open <IP>
user <user/password>
bin
hash
prompt
cd /home/wphfpdw/F021/history
mput *{$DATE}*
bye
END

when I run this is the message
Connected to 10.45.43.63.
220 (vsFTPd 1.2.1)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
331 Please specify the password.
230 Login successful.
200 Switching to Binary mode.
Hash mark printing on (1024 bytes/hash mark).
Interactive mode off.
250 Directory successfully changed.
221 Goodbye.
 
Old 06-05-2007, 01:59 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
If you look carefully at drunna's suggestion you'll notice
*${DATE}*
not
*{$DATE}*
as you've written ...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing all write access files on command line akamad Linux - General 6 03-14-2007 12:37 PM
Need to delete directories with files using command line FTP Zombie13 Linux - Software 2 03-10-2006 11:23 PM
Can somebody like share me to write files to DVD disc in command line? exper Linux - Software 3 08-11-2004 08:58 PM
is there any linux command to download files from any ftp site remotely midnitc Linux - General 3 10-31-2003 09:05 AM
Redhat FTP dates....? Weird Whitehat Linux - General 2 04-08-2003 10:54 AM


All times are GMT -5. The time now is 05:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration