UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old July 14th, 2004, 03:10 AM
huckleberry huckleberry is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 26 huckleberry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 sec
Reputation Power: 0
Question Script to check for and transfer files

Hi,

I need to write a script which effectively checks a particular directory on one server and if it finds any files in the directory, to FTP them to another server and delete the files from the first server. This script needs to run continuously, periodically checking for new upload files in the directory.

Not knowing much about scripting I would be grateful if someone could get me started by letting me know how I go about checking the directory and etc and how I make the script run continuously. I figure it either needs to be a never ending do loop with a sleep command in it, or a cron job of some sort ?

Please help !!
Thanks

Reply With Quote
  #2  
Old July 14th, 2004, 09:24 AM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
If you use cron, you have to check to see if the previous version of the script is still running - depending on how how often you want this thing to run.

Here is a basic skeleton with sleep using co processes in ksh.
This is a starting point...
Code:
#!/bin/ksh
# loop forever
while true
do
    for file in /path/to/directory/*
    do
         export file
        # run a subprocess
        (HOST=hostname
        USER=user
        PASS=password

        exec 4>&1
        ftp -nv >&4 2>&4 |&

        print -p open $HOST
        print -p user $USER $PASS
        print -p cd /remote/directory
        print -p bin
        print -p put $file
        print -p bye

        wait)
       
    done
    sleep 600  # ten minutes
done

Reply With Quote
  #3  
Old July 14th, 2004, 12:00 PM
stevengs stevengs is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Germany
Posts: 394 stevengs User rank is Lance Corporal (50 - 100 Reputation Level)stevengs User rank is Lance Corporal (50 - 100 Reputation Level)stevengs User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 4 h 36 m 24 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
Hi Jim, will he need another for-loop to remove the files as well or should he use the same loop and squeeze it in after the process is finished waiting for the sub to finish? The reason I ask, is because if a file fails to upload, an 'rm -f *' or comparable will possibly erase files that haven't yet been uploaded...

I would even go so far as to suggest building md5 sums into the deal to make sure that the files havent become corrupted during transit. As a bonus, it'd be a good idea to incorporate some compression too.

BTW, I've meant to mention to you that I really enjoy reading your posts. They are extremely informative and you include excellent examples and links. Thanks for sharing your wealth of experience.

-Steven

Reply With Quote
  #4  
Old July 14th, 2004, 12:40 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
If I had to do it somewhat as specified: I'd tar everything, compress it, then FTP the tarball and check the return code or an md5 from the remote box, before I deleted anything locally. Then, connect to the remote box, uncompress, untar the files. FTP loops like this are not my top choice.

In reality, it sounds more like they should have an NFS mounted disk on the second system, so the first system can just copy stuff over as needed. Then have a clean up routine run at night on the first system to delete all files created that day. And if the files are huge, NFS is really appealing.

The other problem with the original design as stated: How do you know the file you are FTP-ing is ready to go? Has the creator of the file finshed creating it, in other words.

Reply With Quote
  #5  
Old July 15th, 2004, 03:47 AM
huckleberry huckleberry is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 26 huckleberry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 sec
Reputation Power: 0
Thanks for the help and all the comments. How indeed will the script know that the uploaded files has finished uploading and is ready to be transferred ?? Any suggestions ?

Also are you able to give me an example of what you mean by 'md5' or point to an example on the web ?

Many thanks

Reply With Quote
  #6  
Old July 21st, 2004, 06:55 AM
huckleberry huckleberry is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 26 huckleberry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 sec
Reputation Power: 0
Fuser

Hi,

Please can someone tell me whether fuser command is able to tell whether a file is still in the process of being uploaded (by HTTP). If not is there another way I can check, assuming its necessary ?

Thanks in advance.

Reply With Quote
  #7  
Old July 28th, 2004, 10:24 AM
banhbo banhbo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 banhbo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Script to check for and email files

Can any one help me with the script to check for files in the directory and email it instead of ftp

Thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Script to check for and transfer files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway