I can start LFTP at x tme - but can i kill process at x time
Hiya,
I normally read until I find an answer but I am stuck so here goes: I have unlimited satellite broadband between 00:00 and 06:00am, out of that time I have to be careful so backing up my site needs to happen then - I would like to learn how to do it on the command line. Here' where I am at: lftp [my bookmark] [set local directory] at:2359 mirror --use-pget-n=5 [remote folder] I am using a low tech electic timer as a killswitch on my router :) - is a command line 'kill switch' possible: at 0600 kill all ? Yesterday I though I ended the proces but I had not - must have been a typo - and it carried on and on and on. I would like to automate it into a script to run periodically eventually - but that is another job. Thanks |
As you have a fixed start date you could use cron to fire up the backup. And use cron to kill it as well.
crontab -e will fire up a editor to edit the cron file of the active user. Add something like Quote:
Quote:
Quote:
Depending on calling on other scripts from start_backup.sh this might not work at first time but should get you started. You sure can use at. But for doing periodic things cron is better suited by far. |
Just wat to say thank you...
Quote:
Wow - that's really cool and really simple - crontab-e who knew eh!. Thanks for taking the time for this - this has made life soooo much easier - really great. Thanks |
echo $$ outputs a pid that is one less than actual lftp pid?
Quote:
Crontab -e - great - been a revelation - however... After checking - the pid outputed from my download script: echo $$ > /run/backup.pid that is saved is 1 less than the actual lftp process id so when my kill lftp script kill $(cat /run/backup.pid) activates at 6.00am it isn't working. e.g backup.pid=3443 $ pgrep lftp 3444 How can I get the actual lftp pid or should I make a variable +1 ? I wish they had taught this in school rather than oxbow lakes :) Thanks - Charles |
You would need to kill all childs of your script. Check out this one http://stackoverflow.com/questions/3...hild-processes
PID+1 could work but can cause some real bad things if in the moment from calling lftp from your script another process gets started. You could also try to run lftp in the background using lftp &. The ampersand puts the process into background. Then with echo $! /runt/lftp.pid save the pid of the last process run in background. Just go with the solution in the link above. |
Thanks zhjim!!! the might pi wakes up at night!
Quote:
pkill -TERM -P $(cat ~/[path to my backup.pid file] so does pkill -TERM $(cat ~/[path to my backup.pid file] Before I go to bed I just shut down openelec on the pi with the remote and leave it to it: 1. auto reboot into Raspian; 2. 11.59 run crontab download script; 3. 05.55 run crontab failsafe kill download script; 4. 06.00 run crontab reboot pi script; 5. @ reboot crontab script creates an autoboot.txt file to make the pi reboot into openelec partition; 6. as openelec starts up - autostart.sh file deletes the autoboot.txt file created; 7. 6.20 little people appear :) 8. normal operation resumes! Thanks for all your help. Charles :hattip: |
You can kill a process by name, but be careful if there is likely to be more than one running as it will kill them all
killall lftp |
All times are GMT -5. The time now is 01:17 AM. |