|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Script to check for and transfer files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|