Skip to main content
Solved

Script question - check that loginwindow is active process?


donmontalvo
Forum|alt.badge.img+36

We will have a policy set up to run between 0000-0600 (using the every30 trigger), and we want it to run only if loginwindow is the active process.

So my thought is the policy will run a script, check running processes, if loginwindow is the process, run the rest of the script, else exit...

Any advice from the scripting gurus? Jared? Thomas? Sean? :)

Thanks,
Don

Best answer by mscottblake

When you say you want to test if the loginwindow is the active process, does that mean you want to only run the script when no one is logged in?

This script is checking the owner of the console. If it's root, then no one is logged in.

#!/bin/bash

current=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

if [[ $current != root ]] 
then
    /bin/echo "$current is logged in, exiting script..."
else
    # run your script
fi
View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+24
  • Honored Contributor
  • 341 replies
  • Answer
  • October 13, 2012

When you say you want to test if the loginwindow is the active process, does that mean you want to only run the script when no one is logged in?

This script is checking the owner of the console. If it's root, then no one is logged in.

#!/bin/bash

current=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

if [[ $current != root ]] 
then
    /bin/echo "$current is logged in, exiting script..."
else
    # run your script
fi

donmontalvo
Forum|alt.badge.img+36
  • Author
  • Legendary Contributor
  • 4293 replies
  • October 13, 2012

@msblake wrote:

does that mean you want to only run the script when no one is logged in?

Yes we need to deploy something that requires an immediate reboot, so we want to do it off hours and only if the computer is logged off (at the login window).

Thanks,
Don


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings