#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    Pausing/starting a python script


    Hi

    I hope you dont mind me posting this but i am hoping someone can help. I had a programmer create me a script that i stop and start using start.sh/stop.sh. The script uses a .py file with the programming details in.

    What i am looking for is a way to run the script using start.sh then it pauses for 20 seconds, then runs for 40 seconds then stops for 20 seconds and so on until i run the stop.sh file.

    Is this possible and if so how would i go about this. I have limted knowledge of python.

    thanks again

    G
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Location
    Bulgaria
    Posts
    3
    Rep Power
    0
    You want to achieve that in Python or in bash shell scripting code?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0
    Thank you for repelying. tbh which ever one would be the easiest to achieve this.

    Basically this is what i use to start and stop the script using start.sh and stop.sh

    Start.sh
    ---------
    #!/bin/bash
    # starts the clockon.py program

    rm -f clockon.out
    nohup /usr/bin/python clockon.py > clockon.out &
    -------------------------------------------------------------------
    and this is what i use to stop the script:

    Stop.sh
    --------
    #!/bin/bash
    # kill the clockon.py process

    pid="$(ps -ef | grep "python clockon.py" | awk '! /grep/ {print $2}')"
    if test -n "$pid" ; then
    kill -9 $pid
    echo Killing process $pid
    else
    echo Process not found
    fi
    ---------------------------------------------------------------------
    Unfortunatly i cannot post the code that is in the .py so if there is easier code to pasue the script then restart it that would be great.

    Thanks

    G
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Location
    Bulgaria
    Posts
    3
    Rep Power
    0
    In bash the command is as simple as:

    sleep 20

  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0
    hi

    so the start.sh would look like this

    #!/bin/bash
    # sleep 20
    # starts the clockon.py program

    rm -f clockon.out
    nohup /usr/bin/python clockon.py > clockon.out &
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0
    i have just tried the above and when i run the start.sh it doesnt pause the script.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Location
    Bulgaria
    Posts
    3
    Rep Power
    0
    of course, because you have commented the "sleep" command with #
    ...
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0
    ah (duh) sorry

    ok i run the script and it paused it for 20 seconds then ran but how do i get it pause for 20 seconds the run for 40 seconds and pause for 20 seconds and so on?

IMN logo majestic logo threadwatch logo seochat tools logo