Scripted LFTP with watchdir ?
Hello everyone,
Really new to linux but I'm learning quite a bit and fairly fast. This is my first question on these forums and I hope I can get pointed in the right direction. Currently I run ubuntu 10 and currently I connect to my box via putty, and manually get files from 1 central ftp and then I take the files there and manually connect to 5 different ftps and send them out. I'm looking to figure out a solution where I can just dump the files into a particular directory on my box like a rtorrent watchdir and a script will pickup the new file and ftp it to all the places I need it to go. I want the script to run in the background and just know a new file hit the directory and take care of it. To save time currently I'm using lftp and i have bookmarks saved with pw for all the ftps. Any help would be greatly appreciated. |
Hi
You could use inotify to watch the directory, and a little script to upload the files. Something like this: Code:
#!/bin/bash |
#!/bin/bash
cd /path/to/the/hot/folder inotifywait -q -m -e close_write,moved_to . --format %f | while read filename ; do lftp "$filename" .... done Thx for the reply. Few questions about the above script. The section in the while lftp "$filename"... In that while would i do something like. lftp mybookmark put "$filename" I understand what you have above but I definetly think its missing something. |
In the while loop, I meant you need to put the commands to upload $filename to the servers. If you need to pass the commands with the filename to lftp as if you typed them, I think it could be something like this:
Code:
#!/bin/bash |
Quote:
Thx again |
"chmod +x scriptname" will make it executable. The script never stops, so you shouldn't run it every 5 min or so. To stop it, you have to press control-c.
You could start it with "nohup scriptname &" and it will run in the background, and continue even when you log out. But first just run it to check if it works. |
Little Issue
Awesome it's running and working perfectly. So if i put it in the background with that cmd how can i check on what it's doing etc?
|
Maybe better to use screen? The script can run in a virtual console and will continue if you get disconnected. Here's a howto on how to use it:
http://www.debian-administration.org/articles/34 |
one last small issue
All setup and working great through screen ty so much.
The only problem im having is if the file name has spaces in it i get no such file when it trys to put it to the ftp. Would i do something like echo "put '$filename' ; exit" | lftp bookmark1 putting ' ' around the filename variable or is there different formating required? |
All times are GMT -5. The time now is 03:56 PM. |