Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Test if program is ever running (not sleeping) over a time period?

  1. #11
    Join Date
    Dec 2007
    Location
    Behind you!!
    Beans
    978
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Test if program is ever running (not sleeping) over a time period?

    Assuming the output is delivered line by line, you can pipe to awk to get just the first column
    Code:
    command | awk '{print $1}'
    Store the output, or run your comparison directly against that in the if clause.

    Bodsda
    computer-howto
    Linux is not windows
    Fluxbox & Flux menu how to
    Programming is an art. Learn it, Live it, Love it!


  2. #12

    Re: Test if program is ever running (not sleeping) over a time period?

    interactive mode is cool, but turn on collection for the I/O

    http://collectl.sourceforge.net/ProcessIOStats.html
    Windows assumes the user is an idiot.
    Linux demands proof.

  3. #13
    Join Date
    Jul 2012
    Beans
    322
    Distro
    Xubuntu 18.04 Bionic Beaver

    Re: Test if program is ever running (not sleeping) over a time period?

    Hmmmm finding collectl too complicated to get to the info I want and to script it all in. Also running mplayer in a loop is causing script std output to break through the image on the terminal (despite my efforts to silence terminal output with "> /dev/null 2>&1" and other such switches)

    Will perhaps look at a crontab job which simply restarts every hour or so, and put up with a blank screen for a minute or so (image random renaming mostly)

    Thanks for all the help though, and collectl is a cool cli tool
    The best things in life are free, so what are we paying for?

  4. #14

    Re: Test if program is ever running (not sleeping) over a time period?

    Quote Originally Posted by Merrattic View Post
    Hmmmm finding collectl too complicated to get to the info I want and to script it all in. Also running mplayer in a loop is causing script std output to break through the image on the terminal (despite my efforts to silence terminal output with "> /dev/null 2>&1" and other such switches)

    Will perhaps look at a crontab job which simply restarts every hour or so, and put up with a blank screen for a minute or so (image random renaming mostly)

    Thanks for all the help though, and collectl is a cool cli tool
    You are correct, whatever you seem to be doing with "mplayer in loops" and redirects, AND cron won't be solved by using collectl.
    But I'm certain you'll figure it out.

    Don't thank me, next time I need to use collectl, I am calling on you.

    Good Luck.
    Windows assumes the user is an idiot.
    Linux demands proof.

  5. #15
    Join Date
    Jul 2012
    Beans
    322
    Distro
    Xubuntu 18.04 Bionic Beaver

    Re: Test if program is ever running (not sleeping) over a time period?

    Revisited this issue and eventually came up with a small bash script using top to capture a "running" (as opposed to sleeping) process:

    Code:
    #!/bin/bash
    
    while :         # infinite loop until condition satisfied
    do
    if top -bcn 1 | grep "mplayer" | grep "R"; then
    # "Do Something"
    break
    fi
    done
    Needs more work to do what I want but just showing the basics for now

    EDIT

    Final script in place:

    Code:
    #!/bin/bash
    
    if top -d 1 -bcn 180 | grep "mplayer" | grep "R"; then
    echo "Running"
    else
    echo passwd | sudo -S shutdown -r now
    fi
    and a crontab job:

    Code:
    */10 * * * * /home/dpf/running.sh
    The "180" means that top will look every second for 3 minutes. If it can grep an "R" in that time (images currently on screen for @ 2.5 mins) then all is OK, if it can't then it restarts the PC (lazy I know, will work on better solution, but it reboots so quickly, it makes not much difference). The crontab runs every 10 minutes. Only problem I have spotted is that sometimes mplayer doesn't move from S to R when it changes pictures (or this hapens so fast I don't see it or top doesn't capture it. top allows fractions of seconds so adjusting the runtime might sort this out. Would be easier if I could figure out a way to capture CPU % from top instead of S & R.....

    [EDIT]

    Neater solution without having to reboot:

    Code:
    #!/bin/bash
    
    if top -d 1 -bcn 180 | grep "mplayer" | grep "R"; then
    echo "Running"
    else
    screen -X quit #(stops gnu-screen)
    echo passwd | sudo -S openvt -f -c 1 ./myscript.sh  #(restarts script on actual physical display)
    fi
    http://ubuntuforums.org/showthread.p...6#post12644806
    Last edited by Merrattic; May 12th, 2013 at 04:44 PM.
    The best things in life are free, so what are we paying for?

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •