Gentoo Forums
Gentoo Forums
Quick Search: in
mirror some folders with lftp, then shutdown
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Poedel
n00b
n00b


Joined: 25 Oct 2006
Posts: 58

PostPosted: Mon Jan 11, 2010 9:14 pm    Post subject: mirror some folders with lftp, then shutdown Reply with quote

Hi friends ..
Sometimes I need to mirror some folders from ftp. I really like lftp. But I do not quite get it's params working from the shell.
I simply want the computer to shutdown after alle jobs are done.
I tried something like this:

Code:
queue stop
queue mirror folder1
queue mirror folder2
...
queue wait all


Now there is a stopped queue to be launched from my bash.

trying this:
Code:
lftp -c queue start && sd

where sd is a sudone alias that is working fine standalone from bash.
why doesn't this programm wait for all downloads to be done like I told at the end of the queue??
After that it could exit and let sd shutdown my laptop.

Could someone please help me?

Thanx in advance!
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Tue Jan 12, 2010 3:04 am    Post subject: Reply with quote

I have never used lftp, so I may be way off, but according to the lftp man page:

1: ...queue wait adds already running jobs to the queue. It doesn't look like it actually queues a wait command. It may, though. You should test this separately.

2: ...the -c option executes the commands and exits (presumably right away), while the -e option doesn't exit at all. Try queueing an exit-command after the wait all and use -e instead.
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
Poedel
n00b
n00b


Joined: 25 Oct 2006
Posts: 58

PostPosted: Tue Jan 12, 2010 5:17 am    Post subject: Reply with quote

nice idea, I tried it immediately.

I added exit to the end of the queue.

Leaving the programm bei exit then right after queueing sets the programm into nohup mode and begins the queue itself.
Okay, I tried suspend instead of exit to leave it first.
No queue start, no nohup. cool.
But!
lftp bookmarkedsite -e queue start && echo hello
did not work.
lftp startet at prompt, said there was a queue but did not download anything, just stand-by. queue start by hand invoked nothing but an empty queue now.
No download. Exiting by hand leaded to the execution of the echo command. mhh?? :(
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Tue Jan 12, 2010 4:12 pm    Post subject: Reply with quote

Hm. Ok, here's a completely different idea. Stick all the commands you want to run in a text file (with wait all and exit at the end), but without the queue in front of each line. Use & at the end of lines to make them run concurrently. Then run:
Code:
lftp -f commands.txt && echo foo

It looks from the man page like a site name is not accepted together with -f, so put an open bookmarkedsite on top of the text file.
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
Poedel
n00b
n00b


Joined: 25 Oct 2006
Posts: 58

PostPosted: Tue Jan 12, 2010 6:45 pm    Post subject: Reply with quote

this might be usefull if the folders were always the same. But first browsing, copying into textfile etc. is quite very inconvinient, you know ;)
I came across an explaining site where the author used -c and -e in combination, so to say as a cascade. Though it is really short I still get not did the point.
He did something different from what I want to do, but I suppose to become conscious of how these two parameters work together. This should be my goal.
I've been so nasty to write an email to the author. I'm excited if he will answer *G*. I will let you know, of course!

http://tutorials.papamike.ca/pub/lftp.html <- the site I mentioned. I will keep an eye on it.. probably I'll get the point soon ..
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Tue Jan 12, 2010 6:53 pm    Post subject: Reply with quote

Actually, I think one of the queue-ideas you have already tried should work, if you quote the command line correctly. In your original command line, you run the command "queue", not "queue start". Try this instead:
Code:
lftp -c "queue start" && echo foo


Though I'm guessing you still need to use -e instead, and with a queued exit at the end.

By the way, the only place I can see that guy use -e and -c together is where -e is an argument to open, not lftp itself.
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
Poedel
n00b
n00b


Joined: 25 Oct 2006
Posts: 58

PostPosted: Tue Jan 12, 2010 7:03 pm    Post subject: Reply with quote

I tried both of your suggestions without success ..
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Tue Jan 12, 2010 7:05 pm    Post subject: Reply with quote

Poedel wrote:
I tried both of your suggestions without success ..

Oh well. Hopefully, you'll get an answer on your mail.
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
Poedel
n00b
n00b


Joined: 25 Oct 2006
Posts: 58

PostPosted: Tue Jan 19, 2010 10:16 pm    Post subject: Reply with quote

okay, we could have guessed this, and it still isn't the efficient way, but it should work indeed.
This is what I had in my email:

Quote:
Hello

I believe you are having problems because you are running two separate
lftp processes. As far as I know lftp processes cannot communicate
between each other.

The queue in your original lftp process is completely separate from
the queue in "lftp -e queue start && shutdown -h now"

There are a few ways of doing what you want. I would recommend doing:

$ lftp user@server && shutdown -h now
[lftp] :~> queue stop
[lftp] :~> queue mirror folder1
[lftp] :~> queue mirror folder2
[lftp] :~> wait all && exit

Alternatively, you could put all the lftp commands in a file and do:

$ lftp -f file && shutdown -h now

- Kyle


this assumes that you know before using lftp if you wanna shutdown after queueing or not.
It was easier if there was a shutdown feature integrated.
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Wed Jan 20, 2010 1:10 pm    Post subject: Reply with quote

You could always request that feature if the app is still in development. In the mean time, stick this at the end of your ~/.bashrc:
Code:
function lftp-sleep () {
  # Get PIDs of running lftp processes
  PIDS="$(pidof lftp)"
  if [ -z "$PIDS" ]; then
    echo "Error: lftp not running!" >&2
    return 1
  fi

  # Wait for PIDs to finish
  for PID in $PIDS; do
    while [ -f /proc/$PID/cmdline ] && [ "$(head -c5 /proc/$PID/cmdline)" == "lftp"$'\0' ]; do
      sleep 10s;
    done
  done

  # Shutdown
  echo "lftp-sleep: Shutting down." >&2
  logger "lftp-sleep: Shutting down."
  shutdown -h now
}


When you want to shut down after a queue, do wait all && exit in lftp and run lftp-sleep in another terminal. It is also abortable with ^C, in case you change your mind. Replace the shutdown-command with an echo to test it out, as usual (and comment out the logger).
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
Poedel
n00b
n00b


Joined: 25 Oct 2006
Posts: 58

PostPosted: Sat Jan 23, 2010 8:02 am    Post subject: Reply with quote

okay, really great script, my dear :lol:
My reply took me so long as I wanted to wait for the developer´s answer fist.
Here an excerpt (last in time on top):

Quote:
Well in that case you would still have to stop lftp and request a shutdown at the end of the queue. Your solution to watch the PID and shutdown seems like a much better solution in my eyes :)


On Fri, Jan 22, 2010 at 11:53 PM, ]] poedel [[ wrote:

Hi Roger,
it would be more convinient. Pretend this situation: I am queuing several folders to be mirrored recursively to my local hard disk drive. While downloading I must leave or it's time for going sleeping. Why should my laptop run all night long? There a feature would be nice to tell lftp while working to shutdown when ready. Now I have to schedule this in advance by starting lftp in the way "lftp && shutdown -h now" to make sure, that it shuts down when queue reaches the two last lines containing wait all and exit.
A bash workaround was made from a user in gentoo forum for me. I can launch this while lftp is at work; it observes the active pids in the processes table and would shutdown when all lftp instances are ready. Even when my queue is already started it seems difficult for me to make lftp shutdown after work.
It was only a feature request, no need for apologies my dear ;)You're doing great work! I just thought about a nice feature.
Have a nice weekend!

LG Klaus

Roger Pixley schrieb:
Apologies for asking but what would be wrong with a traditional script or conditional based scenario?


On Wed, Jan 20, 2010 at 9:23 AM, ]] poedel [[ wrote:

Hi!
I wanted to know a solution for letting my laptop shutdown after the queues have finished. There is only a workaround so far. It was very nice, if you did a shutdown possibility as an implementation into lftp itself.

Greetings from Germany, Klaus


Probably I will go on using your script ;)
I did not have the opportunity to test it, but as far as I know about scripting it looks pretty good!

Thanks again!
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Sun Jan 24, 2010 10:46 pm    Post subject: Reply with quote

No problem! =)

I tested it using sleep instead of lftp, so I think it should work. If not, it probably just needs a tweak here and there.
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
Poedel
n00b
n00b


Joined: 25 Oct 2006
Posts: 58

PostPosted: Tue Feb 09, 2010 5:11 am    Post subject: Reply with quote

yes it does work, one little problem.
When lftp cannot download something it breaks the queue sending an error message.
The task isn't finished, the pid does not disappear, the computer does not shutdown.
Any suggestions to change the behaviour by choosing the right set ??
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Fri Feb 12, 2010 1:04 pm    Post subject: Reply with quote

Hm. Unless lftp has some built in mechanism for this, I don't see an easy way around that. You could see if the cmd:fail-exit setting changes this behaviour (though that may make lftp exit after the first error).
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum