Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question Help !!!! Needed to find system idle time

    i need to create script which will shut down rhel6 workstations if it is not used for 30min for that i need a command which will give me system idle time i.e. that time in which system has not received any mouse or keyboard interrupts.
    i think gnome desktop is also doing same thing, if keyboard/mouse interrupts is not received for some time screen will be locked.

    its really urgent. !!!!

  2. #2
    well, you can just run a loop and check for the elapsed time of the screensaver (if/when it is found running), e.g. (untested):

    while :; do
      pid=$(/sbin/pidof gnome-screensaver)
      if [ $? -eq 0 -a -n "$pid" ]; then
        etime=$(ps -o etime --no-heading -p $pid)
        echo "Screensaver (pid $pid) is running, elapsed time: $etime"
      sleep 1
    However long gnome-session is running would be saved to the etime variable. then you parse it and shut down after whatever time limit you want.

    but i think this solution would only work if someone was logged onto the desktop first (and had a screensaver configured to run), versus the computer just sitting at the graphical login prompt. but maybe that's what you want...

Posting Permissions

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