- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- ftp script with file date and time selection
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2007 07:05 PM
03-15-2007 07:05 PM
We have a file generated by the cron job every 5 minutes past of certain hour during one day time period everyday.
And now we need to ftp those files after they has been generated by the cron job, at the same time we do not want to ftp those files that we have already ftp(ed) before, so we need only to ftp the latest file generated.
The format of the file is as followed :
HOSTNAME_YYMMDDHHMM.gz
So in the directory we have the folowing bunch of files
NHU2CG1_0703140905.gz
NHU2CG1_0703141205.gz
NHU2CG1_0703141605.gz
NHU2CG1_0703141905.gz
.
.
.
Can someone advise how to write the ftp script to transfer those file according the the requirement mentioned above ?
Many thanks
Solved! Go to Solution.
- Tags:
- ftp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2007 07:41 PM
03-15-2007 07:41 PM
Re: ftp script with file date and time selection
1) First you have to ftp one file. Have you found how to do that?
2) The second thing you need to do is to select which files to do. The simplest way to do that is to use touch -r to set a reference file. The first time you want to either set it to the last file you did manually, or to some arbitrary time last year.
Then you can use: find NHU2CG1_*.gz -newer reference-file.
You would want to send all those files to the script/fragment you created for 1) above.
3) In the above process, you need to sort those files so you can set the reference file to the last one you copied.
Now you are all set to do this later.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2007 08:14 PM
03-15-2007 08:14 PM
Re: ftp script with file date and time selection
Please pardon for my ignorant as I have never written any shell script before.
So would appreciate if someone can give some sample script that has been written before and I will try to modify according to my environment.
Thanks !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2007 08:49 PM
03-15-2007 08:49 PM
Solutionunless you insist on using ftp, why don't you use things like rdist and rsync?
Otherwise, please see:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=991609
Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
Your profile shows you only awarded points to 1 of 15 answers !
- Tags:
- rsync
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2007 09:30 PM - edited 10-09-2011 08:40 PM
03-15-2007 09:30 PM - edited 10-09-2011 08:40 PM
Re: ftp script with file date and time selection
>So would appreciate if someone can give some sample script that has been written before and I will try to modify according to my environment.
See Peter's link on how to do ftp. Here is one way to do the selection:
# Create reference file, with date of Jan 1, 1970, if not there
if [ ! -f NHU2CG1_.ref ]; then
touch 0101000070 NHU2CG1_.ref
fi
find NHU2CG1_??????????.gz -newer NHU2CG1_.ref | sort |
while read file; do
echo ftp_one_file $file # ftp this one
touch -r $file NHU2CG1_.ref
done
I'm assuming the names of the files are created based on the times, and the above ascii sort matches the time sort of ll -t.
The "echo ftp_one_file" place is where you would put your script to ftp one file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2007 09:57 PM
03-17-2007 09:57 PM
Re: ftp script with file date and time selection
get a listing of the available remote files and loop of this list to sort out the local available:
cd localdir
# setup your ftp connection
ftpini='_init_commands_
cd remote'
ftp remote <
ls . remote.lst
bye
EOF
while read entry
do
[ -z "$entry" ] && continue
[ -f $entry ] && continue
print get $entry
done
if [ -s getme.lst ]
then
ftp remote<
bin
$(
EOF
fi
You'll have to test this ...
mfG Peter