Announcement

Collapse
No announcement yet.

Script help to restart ktorrent on crash!

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Script help to restart ktorrent on crash!

    hi,
    i am a novice at linux but not in programming.

    Ktorrent crashes very often in teh new release of kubuntu. hence, i have to check if it has crashed every half an hour or so. :-)

    Please advise if i can write a script that will periodically check if ktorrent has crashed, and if it has it will invoke it again?

    thank you


    #2
    Re: Script help to restart ktorrent on crash!

    Depending on your definition of "crash" the following may or may not work:

    Create an executable shell script similar to the following:

    Code:
    #!/bin/bash
    if [ ! "`ps -e | grep 'torrent'`" ]
    then
     /usr/bin/ktorrent
    fi
    Add an according entry to the user's cron job table, e.g.:

    Code:
    * * * * *  ~/torrentRevival

    Comment


      #3
      Re: Script help to restart ktorrent on crash!

      Quick dirt python one:

      Code:
      #! /usr/bin/python
      
      import os
      
      for repeat in range(0,10):
         os.system("ktorrent")
      This will just start ktorrent until it finish 10 times. If it crashes it will be detected as finished and run again. Of course you can change that 10.

      Oh, yes,... a smal bug... you won't be able to close Ktorrent from the gui, the script will start it again .

      Javier.

      Comment


        #4
        Re: Script help to restart ktorrent on crash!

        #! /bin/bash

        pfff... this unicorn is too old fashioned .

        Javier.

        Comment


          #5
          Re: Script help to restart ktorrent on crash!

          Originally posted by javierrivera
          pfff... this unicorn is too old fashioned
          Nope - I just love bashing (whom or what ever ...) as well as to keep real python(s) for critters

          Comment


            #6
            Re: Script help to restart ktorrent on crash!

            @ Unicorn

            by crash i mean.. it just crashes and terminates and the KDE crash assistant comes up. (rather annoying buggy ktorrent!)

            ok
            in the bash file i am about to make:
            can u explain what the line
            " if [ ! "`ps -e | grep 'torrent'`" ] "
            does? (want to learn it also :-P )

            And how do i add an according entry to the user's cron job table? {Sorry if i am being too much of a novice}

            Comment


              #7
              Re: Script help to restart ktorrent on crash!

              @ javierrivera

              the pithon code is damn small and sweet.

              As i have never coded in python, where do i go about writing it and how do i start it. :-)

              thanks

              Comment


                #8
                Re: Script help to restart ktorrent on crash!

                Originally posted by thyscorpion
                by crash i mean ... it terminate
                Excellent

                Originally posted by thyscorpion
                if [ ! "`ps -e | grep 'torrent'`" ]
                "If (K)torrent does not show up in the list of running (!) processes, ..."

                Originally posted by thyscorpion
                how do i add an entry to the user's cron job table
                [Alt][F2] kcron

                Comment


                  #9
                  Re: Script help to restart ktorrent on crash!

                  Originally posted by thyscorpion
                  As i have never coded in python, where do i go about writing it and how do i start it. :-)
                  In any text editor, just as a shell script.

                  Make it executable and run it. Either from the terminal or double clicking it. Again, just as a shell script.

                  Or you can use the python command. ie. python scriptname.py

                  BTW.

                  Code:
                  #! /usr/bin/python
                   
                  import os
                   
                  exit=1
                  while exit<>0 :
                  	exit=os.system("ktorrent")
                  This will only restart ktorrent if it crashed (exit status different from 0), but will let you close it from the GUI (exit status 0).

                  Javier.

                  Comment


                    #10
                    Re: Script help to restart ktorrent on crash!

                    Ah, that'll come in handy for Firefox's segfaults.
                    I'm pretty new to scripting, and I haven't figured out how to do this kind of operation.

                    On scripting itself, I like to stick to (ba)sh, because you're pretty much guaranteed it'll run anywhere (though the same is true for Python nowadays). It's also easier to perform tasks and lower-level communication, because you've got all your commands right there.
                    For external use only.

                    Comment


                      #11
                      Re: Script help to restart ktorrent on crash!

                      Originally posted by SheeEttin
                      On scripting itself, I like to stick to (ba)sh, because you're pretty much guaranteed it'll run anywhere
                      ... except for (K)Ubuntu which is favouring the Dash shell (unless manually "dis-improved", that is) :P

                      Comment


                        #12
                        Re: Script help to restart ktorrent on crash!

                        Originally posted by javierrivera
                        Originally posted by thyscorpion
                        As i have never coded in python, where do i go about writing it and how do i start it. :-)
                        In any text editor, just as a shell script.

                        Make it executable and run it. Either from the terminal or double clicking it. Again, just as a shell script.

                        Or you can use the python command. ie. python scriptname.py

                        BTW.

                        Code:
                        #! /usr/bin/python
                         
                        import os
                         
                        exit=1
                        while exit<>0 :
                        	exit=os.system("ktorrent")
                        This will only restart ktorrent if it crashed (exit status different from 0), but will let you close it from the GUI (exit status 0).

                        Javier.
                        Hi i tried what you indicated...
                        got a problem. i ran my .py file and it loaded ktorrent on its own. and i was pleased. but then when ktorrent crashed, it did not revive it.
                        to show u what how the terminal window looked like, i have attached a snapshot of the terminal.

                        Attached Files

                        Comment


                          #13
                          Re: Script help to restart ktorrent on crash!

                          Ktorrent crash because a bug with DHT. Disable DHT and the crash will stop.
                          If you find a grammar error in my text, is because English is not my native language :-)

                          Comment


                            #14
                            Re: Script help to restart ktorrent on crash!

                            @Mago Lobel

                            OK. but dosn't DHT help a lot in speeding up the downloads? (just asking)

                            Comment


                              #15
                              Re: Script help to restart ktorrent on crash!

                              Not to me. I dont miss it.
                              If you find a grammar error in my text, is because English is not my native language :-)

                              Comment

                              Working...
                              X