Changes between Version 16 and Version 17 of Plugins/Execute


Ignore:
Timestamp:
Mar 11, 2013 3:20:26 PM (8 years ago)
Author:
Cas
Comment:

add bash example and update text

Legend:

Unmodified
Added
Removed
Modified
  • Plugins/Execute

    v16 v17  
    11== Execute == 
    2 The '''Execute''' plugin is only supported from deluge versions 1.3RC2 and up. It gives you the option to run your own scripts (e.a. Bash, Python or any other shell) triggered with different events in Deluge. At this moment only the events '''added''' (when a torrent is added to deluge) and '''complete''' (when a torrent has finished downloading) are supported. More events whill be added in the future. 
     2The '''Execute''' plugin gives you the option to run your own scripts (e.g. `Bash`, `Python` or any other shell) triggered with different events in Deluge. At this moment only the events '''Added''' (when a torrent is added to deluge) and '''Complete''' (when a torrent has finished downloading) are supported. More events will be added in the future. 
    33 
    4 The script to be executed will be supplied with three Torrent variables: 
     4The script to be executed will be supplied with three torrent variables: 
    55 
    66 1. ID (Hash) 
     
    1212== Configuration == 
    1313 
    14 Enable the plugin in the Plugins menu in Preferences. For the webUI; reopen the Preferences menu for the Execute plugin to be available. 
     14Enable the plugin in the Plugins menu in Preferences.  
     15    ''Note: After enabling this plugin Deluge may require restarted for it to work properly.'' 
    1516 
    16 ''Note: After enabling this plugin Deluge may require restarted for it to work properly.'' 
    17  
    18 The events Torrent Complete and Torrent Added can be selected and the full path to the script entered (e.g. /home/user/torrent_added.sh) 
     17The events Torrent Complete and Torrent Added can be selected and the full path to the script entered (e.g. /home/user/execute_script) 
    1918 
    2019[[Image(http://forum.deluge-torrent.org/download/file.php?id=3263)]] 
     
    2221Make sure the script is set to executable:  
    2322{{{ 
    24 chmod u+x /home/user/torrent_added.sh 
     23chmod u+x /home/user/execute_script 
    2524}}} 
    2625Also ensure that it is accessible by the user used to run deluged. 
    2726 
     27Before adding to Deluge, scripts should be tested manually like so: 
     28{{{ 
     29./execute_script "TorrentID" "Torrent Name" "Torrent Path" 
     30}}} 
     31 
    2832== Script Examples == 
     33The following scripts can be used for testing purposes. 
    2934 
    30 === bash === 
     35=== Bash === 
     36{{{ 
     37#!/bin/bash 
     38torrentid=$1 
     39torrentname=$2 
     40torrentpath=$3 
    3141 
    32 === python === 
    33 The following scripts can be used for testing purposses. They can be run from command line like:  
     42echo "Torrent Details: " $torrentname $torrentpath $torrentid  >> /tmp/execute_script.log 
     43}}} 
     44 
     45The variables should show up in the log file.  
    3446{{{ 
    35 ./test.py "var1" "var2" "var3" 
     47tail /tmp/execute_script.log 
     48}}} 
     49 
     50=== Python === 
     51{{{ 
     52#!/usr/bin/env python 
     53from sys import argv 
     54from syslog import syslog 
     55syslog('deluge test: the script started running') 
     56for arg in argv[1:]: 
     57    syslog(arg) 
    3658}}} 
    3759 
     
    4163}}} 
    4264 
     65=== Sendemail script === 
     66As a alternative to the notifications plugin you can send your e-mails through the execute script by using the program `sendemail`. By using `sendemail` it is possible to send e-mails to a smtp server all from one (command)-line. 
    4367 
    44 Python Example script 
    45 {{{ 
    46 #!python 
    47 #!/usr/bin/python 
    48 import sys 
    49 import os 
    50 import syslog 
    51 syslog.syslog('deluge test: the script started running') 
    52 for arg in sys.argv[1:]: 
    53     syslog.syslog(arg) 
    54 }}} 
    55  
    56 === Sendemail script === 
    57 As a alternative to the notifications plugin you can send your e-mails through the execute script by using the program sendemail. I'll explain in short how to set this up. 
    58  
    59 We need to have script to run and the application sendemail installed. 
    60 With sendemail it is possible to send e-mails to a smtp server all from one (command)-line. 
    61 I'm using ubuntu 9.10. If sendemail is available in your repository sendemail can be installed with the command: 
     68To install sendemail on Ubuntu: 
    6269{{{ 
    6370sudo apt-get install sendemail 
     
    6875}}} 
    6976 
    70 Now where going to create the script that utilyzes the sendemail program. The script is named ''torrent_added.sh'' 
     77The script should be named ''torrent_added'' and contain the following: 
    7178{{{ 
    7279#!sh 
     
    8390}}} 
    8491 
    85 In line 2,3 and 4 the variables are assigned to more readable variables.[[BR]] 
    86  
    87 In line 6 and 7 the variables subject and message are filled.[[BR]] 
    88  
    89 In line 9 the message is being written to (in my case) /var/lib/deluge/scripts.log.[[BR]] 
    90  
    91 In line 10 the sendemail program is called. Output is also written to the /var/lib/deluge/scripts.log file.[[BR]] 
    92  
    9392Make sure that you substitute smtp.myisp.com, myemail@domain.com and fromemail@domain.com with your own data! 
    9493 
    95 the same script can be rewritten to be used with the complete event. This way you will get a e-mail when a torrent is started and finished. 
     94This script can be rewritten to be used with the complete event. This way you will get a e-mail when a torrent is started and finished. 
    9695 
    97 The same can also be done with a single python script: 
     96You can also achieve the same outcome with a python script: 
    9897{{{ 
    99 #!python 
    100 #!/usr/bin/python 
     98#!/usr/bin/env python 
    10199import sys  
    102100import smtplib 
     
    114112message = """Put your message here 
    115113 
    116 It can span multiple lines. It can also contain information by specifying 
     114It can span multiple lines and can also contain information by specifying 
    117115%(torrent_id)s or %(torrent_name)s""" % {  
    118116    'torrent_id': torrent_id, 
     
    131129 
    132130This script will search for archives in downloaded content and extract them. Actions are logged as entries in syslog. 
    133 This script can be easily extended to support more compression and archive formats. 
     131It can be easily extended to support more compression and archive formats. 
    134132 
    135133{{{