Launch script on Linux using Putty

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

    #1

    Launch script on Linux using Putty

    Hello,

    I have a python script which runs all the time (using of library
    threading). I would like this scipt to run on a remote linux Os using
    Putty. The problem is, when I close Putty command line window running
    on my Win PC, the python script stops to run too.

    I tried to use cron tables instead. By setting the time and restart
    cron process, but it's not practical.

    Do you know the right way to do this ?

    Regards

  • Michael Hoffman

    #2
    Re: Launch script on Linux using Putty

    Ulysse wrote:
    Hello,
    >
    I have a python script which runs all the time (using of library
    threading). I would like this scipt to run on a remote linux Os using
    Putty. The problem is, when I close Putty command line window running
    on my Win PC, the python script stops to run too.
    >
    I tried to use cron tables instead. By setting the time and restart
    cron process, but it's not practical.
    >
    Do you know the right way to do this ?
    There are a few ways to do this, in order of easiest to most involved:

    1. The easiest is to run nohup on your script in the background:

    $ nohup myscript.py output.txt 2error.txt &

    Then you can disconnect but your script will keep running. Try man nohup
    for more information.

    2. Use GNU screen on your remote terminal, and detach the screen instead
    of logging off.

    3. Set up your script to fork as a daemon. Google for ["python cookbook"
    fork daemon] to find a few recipes for this.
    --
    Michael Hoffman

    Comment

    • Ulysse

      #3
      Re: Launch script on Linux using Putty

      On Apr 2, 12:56 am, Michael Hoffman <cam.ac...@mh39 1.invalidwrote:
      Ulysse wrote:
      Hello,
      >
      I have a python script which runs all the time (using of library
      threading). I would like this scipt to run on a remote linux Os using
      Putty. The problem is, when I close Putty command line window running
      on my Win PC, the python script stops to run too.
      >
      I tried to use cron tables instead. By setting the time and restart
      cron process, but it's not practical.
      >
      Do you know the right way to do this ?
      >
      There are a few ways to do this, in order of easiest to most involved:
      >
      1. The easiest is to run nohup on your script in the background:
      >
      $ nohup myscript.py output.txt 2error.txt &
      >
      Then you can disconnect but your script will keep running. Try man nohup
      for more information.
      >
      2. Use GNU screen on your remote terminal, and detach the screen instead
      of logging off.
      >
      3. Set up your script to fork as a daemon. Google for ["python cookbook"
      fork daemon] to find a few recipes for this.
      --
      Michael Hoffman
      Thanks a lot but in my situation :

      1. nohup seems not to be installed on my "reduced linux distribution".
      It's a OpenWrt tunning on my WRT54GL Broadband router.

      2. I have looked for the way I can "detach the screen" with Putty but
      I've not found (May be you can precise ?)

      3. The "fork daemon" script found on http://aspn.activestate.com/ASPN/Coo.../Recipe/278731
      seems to be as huge as my own script and little bit hard to undestand.

      So maybe "detach the screen" ?

      Thanks

      Comment

      • ihccab

        #4
        Re: Launch script on Linux using Putty

        On Apr 2, 1:51 pm, "Ulysse" <maxim...@gmail .comwrote:
        On Apr 2, 12:56 am, Michael Hoffman <cam.ac...@mh39 1.invalidwrote:
        >
        >
        >
        Ulysse wrote:
        Hello,
        >
        I have a python script which runs all the time (using of library
        threading). I would like this scipt to run on a remote linux Os using
        Putty. The problem is, when I close Putty command line window running
        on my Win PC, the python script stops to run too.
        >
        I tried to use cron tables instead. By setting the time and restart
        cron process, but it's not practical.
        >
        Do you know the right way to do this ?
        >
        There are a few ways to do this, in order of easiest to most involved:
        >
        1. The easiest is to run nohup on your script in the background:
        >
        $ nohup myscript.py output.txt 2error.txt &
        >
        Then you can disconnect but your script will keep running. Try man nohup
        for more information.
        >
        2. Use GNU screen on your remote terminal, and detach the screen instead
        of logging off.
        >
        3. Set up your script to fork as a daemon. Google for ["python cookbook"
        fork daemon] to find a few recipes for this.
        --
        Michael Hoffman
        >
        Thanks a lot but in my situation :
        >
        1. nohup seems not to be installed on my "reduced linux distribution".
        It's a OpenWrt tunning on my WRT54GL Broadband router.
        >
        2. I have looked for the way I can "detach the screen" with Putty but
        I've not found (May be you can precise ?)
        >
        3. The "fork daemon" script found onhttp://aspn.activestat e.com/ASPN/Cookbook/Python/Recipe/278731
        seems to be as huge as my own script and little bit hard to undestand.
        >
        So maybe "detach the screen" ?
        >
        Thanks
        Try running the script with the ampersand (&) at the end.

        ../myscript.py &

        that will put it in the background and you can exit the Putty window.

        You can start the script at boot by adding it to rc.local using the
        full path to the script.

        /path/to/myscript.py &

        Comment

        • ihccab

          #5
          Re: Launch script on Linux using Putty

          On Apr 2, 2:07 pm, "ihccab" <ihc...@gmail.c omwrote:
          On Apr 2, 1:51 pm, "Ulysse" <maxim...@gmail .comwrote:
          >
          >
          >
          On Apr 2, 12:56 am, Michael Hoffman <cam.ac...@mh39 1.invalidwrote:
          >
          Ulysse wrote:
          Hello,
          >
          I have a python script which runs all the time (using of library
          threading). I would like this scipt to run on a remote linux Os using
          Putty. The problem is, when I close Putty command line window running
          on my Win PC, the python script stops to run too.
          >
          I tried to use cron tables instead. By setting the time and restart
          cron process, but it's not practical.
          >
          Do you know the right way to do this ?
          >
          There are a few ways to do this, in order of easiest to most involved:
          >
          1. The easiest is to run nohup on your script in the background:
          >
          $ nohup myscript.py output.txt 2error.txt &
          >
          Then you can disconnect but your script will keep running. Try man nohup
          for more information.
          >
          2. Use GNU screen on your remote terminal, and detach the screen instead
          of logging off.
          >
          3. Set up your script to fork as a daemon. Google for ["python cookbook"
          fork daemon] to find a few recipes for this.
          --
          Michael Hoffman
          >
          Thanks a lot but in my situation :
          >
          1. nohup seems not to be installed on my "reduced linux distribution".
          It's a OpenWrt tunning on my WRT54GL Broadband router.
          >
          2. I have looked for the way I can "detach the screen" with Putty but
          I've not found (May be you can precise ?)
          >
          3. The "fork daemon" script found onhttp://aspn.activestat e.com/ASPN/Cookbook/Python/Recipe/278731
          seems to be as huge as my own script and little bit hard to undestand.
          >
          So maybe "detach the screen" ?
          >
          Thanks
          >
          Try running the script with the ampersand (&) at the end.
          >
          ./myscript.py &
          >
          that will put it in the background and you can exit the Putty window.
          >
          You can start the script at boot by adding it to rc.local using the
          full path to the script.
          >
          /path/to/myscript.py &
          To check that is is running in the background, do:
          ps -ef | grep myscript.py

          You will see the process table entry for your script with the PID and
          other info.

          Comment

          • Michael Hoffman

            #6
            Re: Launch script on Linux using Putty

            [Michael Hoffman]
            >1. The easiest is to run nohup on your script in the background:
            >>
            >$ nohup myscript.py output.txt 2error.txt &
            >>
            >Then you can disconnect but your script will keep running. Try man nohup
            > for more information.
            >>
            >2. Use GNU screen on your remote terminal, and detach the screen instead
            >of logging off.
            >>
            >3. Set up your script to fork as a daemon. Google for ["python cookbook"
            >fork daemon] to find a few recipes for this.
            [Ulysse]
            1. nohup seems not to be installed on my "reduced linux distribution".
            It's a OpenWrt tunning on my WRT54GL Broadband router.
            If you are running bash, you can do this:

            $ myscript.py &
            [1] 30834

            $ disown %1
            2. I have looked for the way I can "detach the screen" with Putty but
            I've not found (May be you can precise ?)
            Google for GNU screen. But it probably won't be installed either, if
            nohup isn't.
            3. The "fork daemon" script found on http://aspn.activestate.com/ASPN/Coo.../Recipe/278731
            seems to be as huge as my own script and little bit hard to undestand.
            OK, another alternative is to simulate nohup yourself, using the signal
            module. You might want to read the docs and search the cookbook for
            examples of its use. I think it would be something like:

            import signal

            signal.signal(s ignal.SIGHUP, signal.SIG_IGN)
            --
            Michael Hoffman

            Comment

            • Grant Edwards

              #7
              Re: Launch script on Linux using Putty

              On 2007-04-02, Michael Hoffman <cam.ac.uk@mh39 1.invalidwrote:
              >>1. The easiest is to run nohup on your script in the background:
              >>>
              >>$ nohup myscript.py output.txt 2error.txt &
              >>>
              >>Then you can disconnect but your script will keep running. Try man nohup
              >> for more information.
              >>>
              >>2. Use GNU screen on your remote terminal, and detach the screen instead
              >>of logging off.
              >>>
              >>3. Set up your script to fork as a daemon. Google for ["python cookbook"
              >>fork daemon] to find a few recipes for this.
              >
              [Ulysse]
              >1. nohup seems not to be installed on my "reduced linux distribution".
              >It's a OpenWrt tunning on my WRT54GL Broadband router.
              >
              If you are running bash, you can do this:
              He's not running bash. He's running busybox's shell.

              [He'd be far better off asking his question in an OpenWRT or
              Busybox forum, since it's got absolutely nothing to do with
              Python.]

              --
              Grant Edwards grante Yow! They don't hire
              at PERSONAL PINHEADS,
              visi.com Mr. Toad!

              Comment

              • Michael Hoffman

                #8
                Re: Launch script on Linux using Putty

                [Michael Hoffman]
                >If you are running bash, you can do this:
                [Grant Edwards]
                He's not running bash. He's running busybox's shell.
                There's a nohup applet for busybox.
                [He'd be far better off asking his question in an OpenWRT or
                Busybox forum, since it's got absolutely nothing to do with
                Python.]
                I was going to say that originally, but then I realized that the daemon
                solution is on-topic. So is masking SIGHUP.
                --
                Michael Hoffman

                Comment

                • Ulysse

                  #9
                  Re: Launch script on Linux using Putty

                  On Apr 2, 8:54 pm, Michael Hoffman <cam.ac...@mh39 1.invalidwrote:
                  [Michael Hoffman]
                  >
                  If you are running bash, you can do this:
                  >
                  [Grant Edwards]
                  >
                  He's not running bash. He's running busybox's shell.
                  >
                  There's a nohup applet for busybox.
                  >
                  [He'd be far better off asking his question in an OpenWRT or
                  Busybox forum, since it's got absolutely nothing to do with
                  Python.]
                  >
                  I was going to say that originally, but then I realized that the daemon
                  solution is on-topic. So is masking SIGHUP.
                  --
                  Michael Hoffman
                  Actually the "./myscript.py &" command seems to work well. I can close
                  the Putty console, and then after logging the command "top" show me
                  that my process is still running.

                  Comment

                  Working...