









|
[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
[NMLUG] Move files via FTP
Thanks for the reply Ed.
Having googled more I did find an article from Linux Journal regarding automating ftp transfers and the use of .netrc to automate logins. I stole/munged/hacked this script together. See any obvious flaws?
I have this set up to run every hour via cron. I currently have stdout going to a log file for each transfer so I can check for success or not on each transfer. It would be nice if I could have the entire session appended to previous sessions so I can have a daily log of all activity to reflect back on. I would also need to have this log rotated daily but haven't figured out how to do the logrotate thing yet.
Tim
#!/bin/bash
# ftp-jlscan
# This script will scan a directory and transmit its contents to JL-Scan's FTP server
logfile=/var/log/ftp-jlscan.log
scandir=/shares/temp/gm-warranty-scans
notify=temerick@vtaig.com
cd $scandir
for warrantyfile in `find . -cmin +5 -type f -printf %P'\040'`
do
ftp -i -v > $logfile 2>&1 <<mayday
open jlscan.com
cd /new
put $warrantyfile
quit
mayday
if egrep "421 S|426 C|450 R|500 S|501 S|503 B|550 R|553 R" $logfile > /dev/nul 2>&1
then
cat $logfile | mail -s "Error transmitting a warranty file to JL-Scan" $notify
else
rm -fr $warrantyfile
fi
done
Ed Heron <Ed@Heron-ent.com> wrote:
You might want to use -cmin to get changed time, not access time. This
might need some tweeking, because I haven't actually set up a test
environment or actually tried find like that.
---
#!/bin/bash
dir_scan="/home/figment/ftp" # $1 is directory to check in
ftp_host="ftp.local.com" # host to put file
ftp_dir="subdirectory" # directory on ftp host to put file
cd $dir_scan
for file in `find . -cmin +15`; do
file_exist='( echo "cd $ftp_dir" ; echo " ; echo "quit" ) | ftp $ftp_host
| grep $file`
if [ "$file_exist" ]; then echo | mail -s "ftp script:replacing $file"
notify@local.com ; fi
( echo "cd $ftp_dir" ; echo "put $file" ; echo "quit" ) | ftp $ftp_host
mv $file ../backup
done
---
disclaimer: this is just a figment of your imagination, I'm not really here.
----- Original Message -----
From: Tim Emerick
To: nmglug@nmglug.org ; nmlug nmlug
Sent: Wednesday, July 05, 2006 5:13 PM
Subject: [NMLUG] Move files via FTP
I have a small project that I need some help with. My bash scripting skills
are terrible and I haven't been able to find a utility to do what I want
which is this in a nutshell.
Here's some pseudo-code:
1. Look at a particular directory on local computer.
2. List all files that are older than 15 minutes (file might still be in the
process of creation)
3. Copy those files to an FTP server that requires a username/password
combo.
4. If the file already exists on the FTP server then throw somebody an email
letting them know.
5. If the transfer is successful then delete the original (or move it to
another directory).
I would like to run this every hour via cron.
Anything out there already existing?
Thanks!
Tim
PS. Doing a little googling while I was composing helped me figure out a
couple of things.
1. I can get a listing of files older than 15 minutes by using the
following. find . -amin +15
2. I can use .netrc to automagically login to the remote ftp server with my
credentials.
3. How do I do 2 things with my list of found files??? (ftp put and then
delete/move)?
4. How do I get an email of just file tranfer errors? (file already exists,
etc)
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates
starting at 1?/min.
_______________________________________________
NMLUG mailing list
NMLUG@nmlug.org
http://www.nmlug.org/mailman/listinfo/nmlug
_______________________________________________
NMLUG mailing list
NMLUG@nmlug.org
http://www.nmlug.org/mailman/listinfo/nmlug
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.b9.com/pipermail/nmlug/attachments/20060705/39306b8f/attachment.htm
|
|