cron query

Discussion in 'Other Operating Systems' started by von Stalhein, Jul 3, 2009.

  1. von Stalhein

    von Stalhein Member

    Joined:
    May 3, 2002
    Messages:
    1,906
    Location:
    Thurgoona NSW
    Hello all,
    I'm trying to set up a cron job to start Deluge when my off peak quota is operating (twixt 2am and 10am).

    I used the info on the Deluge Wiki with Gnome-Schedule but I can't get it to start

    Code:
    0 2 * * * deluge -u console -a "config --set max_active_limit 100"
    
    Code:
    0 10 * * *deluge -u console -a "config --set max_active_limit 0"
    
    Can anyone see anything wrong with that code, and what needs to be working (other than the machine!!!) for it to start?
     
  2. PhuckNut

    PhuckNut Member

    Joined:
    Sep 3, 2003
    Messages:
    546
    is that in user crontab, or system crontab ?

    If it's in system crontab, you should have a user before the command.
     
  3. OP
    OP
    von Stalhein

    von Stalhein Member

    Joined:
    May 3, 2002
    Messages:
    1,906
    Location:
    Thurgoona NSW
    OK, ta, I'll try that - I assume it's a system crontab.
     
  4. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    First up, you must specify the full path to programs listed in cron, ie: instead of "transmission", you'd use "/usr/bin/transmission".

    Secondly, if it's a GUI app, then you need to specify the display for it to start on. This is how I start Transmission with a cron job:

    Code:
    0 0 * * * DISPLAY=:0 /usr/bin/transmission %F &
    
    ...will start it at midnight on the first X display. The ampersand on the end tells cron not to wait for Transmission to return an exit code (ie: don't wait for the program to quit - start it as a background process).

    Editing a specific user's crontab can be achieved with:
    Code:
    $ sudo crontab -u jbloggs -e
    
    ...which will edit jbloggs' crontab. If you just say "sudo crontab -e" you will edit root's crontab instead.
     
  5. OP
    OP
    von Stalhein

    von Stalhein Member

    Joined:
    May 3, 2002
    Messages:
    1,906
    Location:
    Thurgoona NSW
    OK HyRax1, I'm away :D

    It starts the GUI, but there are some error messages in the terminal, viz
    Code:
    close failed in file object destructor:
    Error in sys.excepthook:
    
    Original exception was:
    /var/lib/python-support/python2.6/deluge/ui/gtkui/mainwindow.py:63: GtkWarning: gtk_toolbar_set_icon_size: assertion `icon_size != GTK_ICON_SIZE_INVALID' failed
      "glade/main_window.glade"))
    
    This doesn't seem to affect the program operation. I got lazy and used the scheduler - the only change to your suggestion was I had to use a | instead of the %

    To stop it at 10 am, is it the same syntax, or is there another parameter to terminate the program?
    TIA :thumbup:
     
  6. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    Perfectly normal. Not every iconset in every theme is perfect. :)

    Two ways to do it. If the program is properly written, it should respond and shutdown cleanly with:
    Code:
    $ killall <program name>
    
    eg:
    
    $ killall transmission
    
    ...which should be the same as clicking the close button of that program's GUI with your rodent.

    Unfortunately some programs don't respond politely and are a bit stubborn. For these programs you can be a bit more forceful with the "kill" command.
    Code:
    $ kill <program pid>
    
    ...should do the same as killall, which for a stubborn program isn't likely to be much. To terminate with extreme prejudice, use:
    Code:
    $ kill -9 <program pid>
    
    ...which no application can stop (muhahahahahaaaaa).

    To get a program's PID (Process ID), use the command:
    Code:
    $ ps aux | grep <program name>
    
    ...and look at the left-most number. That's the PID. If you want to get really classy and get the PID and feed it to the kill command in one line, check out my blog entry about it, but in short:
    Code:
    $ ps -eo pid,args | grep <program name> | awk '{print $1}' | xargs -I {} kill -9 {}
    
    EDIT: Incidentally, I'm using Deluge now as well instead of Transmission. My crontab looks like this:
    Code:
    # Start the Deluge BitTorrent daemon at midnight and the web UI one minute later (since it seems to have issues starting when there's no daemon running first).
    0 0 * * * /usr/bin/deluged &
    1 0 * * * /usr/bin/deluge --ui web &
    
    # Terminate the Deluge BitTorrent daemon at midday to prevent using peak quota.
    # Note that the web UI keeps running but can't operate without the daemon.
    0 12 * * * killall deluged
    
    I don't use the GTK interface - my Deluge runs on my headless server and I control it via the (rather cool) Ajax web interface.
     
    Last edited: Jul 6, 2009
  7. OP
    OP
    von Stalhein

    von Stalhein Member

    Joined:
    May 3, 2002
    Messages:
    1,906
    Location:
    Thurgoona NSW
    Awesome, works a treat!

    Thanks again HyRax1 - as usual informative, and with teh bonus educational aspect at no charge!
     
  8. cleary

    cleary Mental in the Face

    Joined:
    Apr 25, 2003
    Messages:
    4,244
    Location:
    Griffith NSW
    or you can use:
    Code:
    pidof <program-name>
    
    Code:
    kill $(pidof <program name>)
     
    Last edited: Jul 7, 2009
  9. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    You learn something new everyday - cheers for that. :)
     
  10. Crinos

    Crinos Member

    Joined:
    Jul 1, 2002
    Messages:
    4,026
    Location:
    Tasmania
    Please don't encourage the use of "kill -9" :(

    Programs catch exit signals for a reason, and "kill -9" is like shutting down your computer by yanking the power plug.
     
  11. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    That's why I mentioned "killall" first. "kill -9" is only as a last resort.
     
  12. Iroquois

    Iroquois Member

    Joined:
    Jun 27, 2001
    Messages:
    1,958
    deleted post
     
    Last edited: Mar 25, 2016
  13. Crinos

    Crinos Member

    Joined:
    Jul 1, 2002
    Messages:
    4,026
    Location:
    Tasmania
    I know, I've just seen too many trigger happy people SIGKILLing everything in sight and then wondering why everything is corrupted and buggered ;)
     
  14. BIPyjamas

    BIPyjamas Member

    Joined:
    Jun 28, 2001
    Messages:
    707
    Location:
    Hong Kong
    Also,

    Code:
    $ pkill <process_name>
     
  15. OP
    OP
    von Stalhein

    von Stalhein Member

    Joined:
    May 3, 2002
    Messages:
    1,906
    Location:
    Thurgoona NSW
    Geez, I didn't expect to start a sort of Spanish Inquisition! :)

    I went with the "killall deluge" command, and it seems to have done the trick without any issues.

    BTW, what's the diff between deluge and deluged?
     
  16. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    deluged is the daemon that actually does the work of downloading torrents. deluge is just the user interface to the daemon.
     
  17. OP
    OP
    von Stalhein

    von Stalhein Member

    Joined:
    May 3, 2002
    Messages:
    1,906
    Location:
    Thurgoona NSW
    So the go to make it run without the GUI is to use the "deluged" command?

    Not that the GUI imprisons a heap of cpu cycles anyway.
     
  18. HyRax1

    HyRax1 ¡Viva la Resolutión!

    Joined:
    Jun 28, 2001
    Messages:
    7,745
    Location:
    At a desk
    That is correct.
     
  19. OP
    OP
    von Stalhein

    von Stalhein Member

    Joined:
    May 3, 2002
    Messages:
    1,906
    Location:
    Thurgoona NSW
    Ok thanks :thumbup:


    Now, what else can I cron..............
     

Share This Page