Script question - check that loginwindow is active process?

donmontalvo
Esteemed Contributor III

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

--
https://donmontalvo.com
1 ACCEPTED SOLUTION

mscottblake
Valued Contributor

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 solution in original post

2 REPLIES 2

mscottblake
Valued Contributor

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
Esteemed Contributor III

@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

--
https://donmontalvo.com