This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Feature Request: shut down after dowloading & execute co

Tags: None
(comma "," separated)
chris_ds
Registered Member
Posts
6
Karma
0
I'm a student and I can't pay a 24/7 energy bill.

If the pc would shut down after downloading this would be very appreciated.

Additionally a feature like "do command x then y then z after download" would be cool, too...
Like: 1. scan Folder for virus, 2. extract multi .rar file, 3. shut down pc...

Is that possible?
George
Moderator
Posts
5421
Karma
1

Tue Oct 09, 2007 6:39 pm
Not at the moment.

We are planning to add scripting in the KDE4 version, so this could make this possible.
chris_ds
Registered Member
Posts
6
Karma
0

Thu Oct 11, 2007 11:09 am
Thx for the reply. Can't wait to see it.

But whats up with auto-shut down? should be possible with a scheduler plugin, right?
dvanaise
Registered Member
Posts
5
Karma
0

Sat Oct 13, 2007 9:11 pm
this script can do that


Code: Select all
echo Choose Torrent Number:
for x in `dcop ktorrent KTorrent getTorrentNumbers 0`
   do echo $x - `dcop ktorrent KTorrent getTorrentInfo $x | sed -n 1p`;
done

echo Choose Torrent Number:
read x
echo Enter command/script to execute:
read value


while [ 1 ]
do
   if [ "`dcop ktorrent KTorrent getTorrentInfo $x | sed -n 10p`" == "100,00 %" ];
      then  $value
   fi
    sleep 60
done
chris_ds
Registered Member
Posts
6
Karma
0

Mon Oct 15, 2007 8:37 pm
Oh need to test that. Thank you!

Hmm, seems to work, waiting for the shut down...

But how can I manage to get the command executed when all torrents are finished? This script shuts down when the chosen torrent is done, right?

Cool script, I should learn scripting...
skyhook19
Registered Member
Posts
1
Karma
0

Tue Oct 16, 2007 12:38 am
I would also really like to see a feature that shuts down my computer after all my torrents have finished seeding, it's one of my favourite features in uTorrent.
dvanaise
Registered Member
Posts
5
Karma
0

Tue Oct 16, 2007 6:11 am
I think this should work but need some testing
with "sleep" you can change time of checking torrents in seconds

Code: Select all

echo Enter command/script to execute:
read value

while [ 1 ]
do
   y=1;

   for x in `dcop ktorrent KTorrent getTorrentNumbers 0`
      do   
         if [ "`dcop ktorrent KTorrent getTorrentInfo $x | sed -n 10p`" != "100,00 %" ];
            then  y=0;
         fi
      done

   if [ "$y" == "1" ];
      then  $value
   fi
       sleep 60
done




sorry for my bad english
chris_ds
Registered Member
Posts
6
Karma
0

Tue Oct 16, 2007 7:27 am
Thank you, I will test the new script soon.

By the way, is there a way to shutdown like KDE does?
If I shutdown in KDE and reboot after that, all my programms are restored. If I shutdown with shutdown -h or halt command KTorrent and the other programs are gone...?

... bad english is no problem for me, because I am no native speaker as well (as you might have noticed) :P
dvanaise
Registered Member
Posts
5
Karma
0

Tue Oct 16, 2007 6:35 pm
dcop ksmserver default logout 0 -1 -1

First parameter: confirm
Obey the user's confirmation setting: -1
Don't confirm, shutdown without asking: 0
Always confirm, ask even if the user turned it off: 1
Second parameter: type
Select previous action or the default if it's the first time: -1
Only log out: 0
Log out and reboot the machine: 1
Log out and halt the machine: 2
Third parameter: mode
Select previous mode or the default if it's the first time: -1
Schedule a shutdown (halt or reboot) for the time all active sessions have
exited: 0
Shut down, if no sessions are active. Otherwise do nothing: 1
Force shutdown. Kill any possibly active sessions: 2
Pop up a dialog asking the user what to do if sessions are still active: 3

Code: Select all
dcop ksmserver ksmserver logout 0 0 0


just replace 0 0 0 with options that you prefer
chris_ds
Registered Member
Posts
6
Karma
0

Wed Oct 17, 2007 6:22 pm
Awesome! KDE shuts down like I hoped for.
I tried to edit the code the way I need it. As I have no idea of scripting, The code is pretty messed up.
But it works!

It now checks, if there are active downloads (it waits for active DLs so you can start it right along with Ktorrent, even if you have no downloads at the moment), if there are completed downloads (it doesnt shut down the pc if there are no completed downloads, because this always means the user has deleted the active torrents manually) and checks if the user doesnt want the script to turn off the computer.

Because I got so much help on this forum I would like to thank you all and espacially dvanaise for his code and info and let you participate on my experiments.
Therefore I attched the code so you can check it out and maybe have some fun with it.

Code: Select all
echo KTorrent-Shutdown-Script:
#read value

while [ 1 ]
do
   if [ "$r" != "0" ];
   then echo Warte auf aktive Downloads.
   fi
   r=0
   u=`dcop ktorrent KTorrent getTorrentNumbers 1` #check for active downloads
   while [ "$u" != "" ] && [ "$r" == "0" ] #if there are active downloads start shutdown-part
   do
      echo Aktive Downloads erkannt, das Shutdown-Script wurde aktiviert!
         while [ "$r" == "0" ]
         do
         y=1;
         
         c=`dcop ktorrent KTorrent getTorrentNumbers 2` #check for completed downloads
         u2=`dcop ktorrent KTorrent getTorrentNumbers 1` #check for active downloads in order to restart the script
            for x in `dcop ktorrent KTorrent getTorrentNumbers 0`
            do   
               if [ "`dcop ktorrent KTorrent getTorrentInfo $x | sed -n 10p`" != "100,00 %" ];
               then  y=0;
               fi
            done
            
               if [ "$c" != "" ];    #only if there are completed downloads execute command
                        #if there are no completed DLs the user might have deleted the download manually
               then
                  if [ "$y" == "1" ];
                     #then  $value
                     then   #xmessage to user, who can cancel the shutdown sequence
                     echo PC fährt in 5 Minuten herunter!
                     xmessage -center -timeout 300 -buttons "Sofort herunterfahren":0,Abbrechen:2 "PC wird in 5 Minuten heruntergefahren!"
                        case $? in
                        0) xmessage -center -timeout 5 "PC fährt jetzt herunter";dcop ksmserver ksmserver logout 0 2 0 ;;
                        2) xmessage -center -timeout 5 "Abbruch durch den Benutzer, warte auf neue Downloads" & r=1 ;;
                        esac
                  fi
               fi

         if [ "$c" == "" ] && [ "$u2" == "" ]; #if there are no active or completed DLs restart script
         then r=1
         echo Keine aktiven Downloads erkannt, das Shutdown-Script wurde deaktiviert!
         fi
         sleep 60 #repeat
         done
         
   done
   sleep 60 #else check for active DLs every ... seconds
done
dvanaise
Registered Member
Posts
5
Karma
0

Thu Oct 18, 2007 7:37 pm
That's great but can you post all messages in English, please?I can't understand German but want to translate them in my native language
I'll cast an eye at script in several days
chris_ds
Registered Member
Posts
6
Karma
0

Mon Oct 22, 2007 7:52 pm
yeah of course, i enhanced the script about an "extract and scan for virus" feature:

Code: Select all
echo KTorrent-Shutdown-Script:
#read value

while [ 1 ]
do
   if [ "$r" != "0" ];
   then echo Waiting for active downloads.
   fi
   r=0
   u=`dcop ktorrent KTorrent getTorrentNumbers 1` #check for active downloads
   while [ "$u" != "" ] && [ "$r" == "0" ] #if there are active downloads start shutdown-part
   do
      echo Active downloads detected, shut-down script activated!
         while [ "$r" == "0" ]
         do
         y=1;
         
         c=`dcop ktorrent KTorrent getTorrentNumbers 2` #check for completed downloads
         u2=`dcop ktorrent KTorrent getTorrentNumbers 1` #check for active downloads in order to restart the script
            for x in `dcop ktorrent KTorrent getTorrentNumbers 0`
            do   
               if [ "`dcop ktorrent KTorrent getTorrentInfo $x | sed -n 10p`" != "100,00 %" ];
               then  y=0;
               fi
            done
            
               if [ "$c" != "" ];    #only if there are completed downloads execute command
                        #if there are no completed DLs the user might have deleted the download manually
               then
                  if [ "$y" == "1" ];
                     #then  $value
                     then   #xmessage to user, who can cancel the shutdown sequence
                     echo PC shutting down in 5 minutes!
                     echo Extracting and checking files. This can take some time...
                     /path-to-extract-scan-script/extract-scan-script    ####### Replace with your path, or simply remove it ######
                     xmessage -center -timeout 300 -buttons "Shut-down now!":0,Cancel:2 "PC will shut down in 5 minutes!"
                        case $? in
                        0) xmessage -center -timeout 5 "PC shutting down now!";dcop ksmserver ksmserver logout 0 2 0 ;;
                        2) xmessage -center -timeout 5 "Canceled by user, waiting for new active Downloads." & r=1 ;;
                        esac
                  fi
               fi

         if [ "$c" == "" ] && [ "$u2" == "" ]; #if there are no active or completed DLs restart script
         then r=1
         echo No active Downloads detected, shutdown-script deactivated!
         fi
         sleep 60 #repeat
         done
         
   done
   sleep 60 #else check for active DLs every ... seconds
done



This is the extract script. If you do not need it, just remove the line with the path to the script:

Code: Select all
#!/bin/bash

find path-to/Torrent-Downloads -name "*.rar" -print0 | xargs -0 -t -r -i mkdir {}_autoextracted/  ## searches for .rar-files and creates a directory to extract to
find path-to/Torrent-Downloads -name "*.rar" -print0 | xargs -0 -t -r -i unrar -o- -p- -sl4187593113 x {} {}_autoextraced/  ## extracts .rar-files to the just made directories, but only to a given maximum size (file larger than ca. 3 gigs are not extracted - you can change that by deleting or editing the "-slXXXXXXXXX" argument)

find path-to/Torrent-Downloads -name "*.rar" -print0 | xargs -0 -t -r -i antivir --heur-macro --allfiles -del -s -z -r1 --heur-level=3 {}_autoextracted/  ## This is used to scan the extraced rar files with antivir. You can do that first, before extracting it, if it feels safer to you, but I don't trust in Antivirs capabilities of scanning in archives
exit


Thats it. I am testing it for several days now and it seems to work very well. The extract script is a great time saver. But be sure to get the right antivir settings to delete any found virus, because you won't be there to decide what to do (hope I found the right command).
The translation was made under light time pressure, please feel free to correct the mistakes and have some fun in using and testing it.

8) cu soon


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell