Principle: Use the screen in Ubuntu to protect the status of the process (gnome-screensaver-command-q) (its principle is to automatically lock the screen after the system is idle for a certain period of time ), determines that the computer is idle and executes a specificProgram.
# ! /Bin/sh
# This program is used to end the specified program after a certain period of time.
# /Usr/bin/mentohust-K can also be used to end the mentohust Process
Taskkill ()
{
If [$ # -Ne 2]; then
PID = $ (PS ax | grep $1 | Awk '{ If ( $0 !~ /Grep/) {print $1 }}')
# Echo "pid = $ PID"
If [-N " $ PID " ]; Then
Kill-9 $ PID >/Dev/null 2> & 1
Fi
Return 0
Fi
# Echo "Num: $"
Return 1
}
Process = " Mentohust "
SSN = " The screen saver status is inactive. "
SSA =" The screen saver status is active. "
Log = " /Tmp/taskkill. Log $ "
While :
Do
State = $ (gnome-screensaver-command-Q 2>/dev/null)
If [ " $ State " = " $ SSA " ]
Then
Taskkill $ Process
Break
Else
Echo " The Screen Saver is still not active " $ (Date)> $ Log
Sleep 300
Fi
Done
Echo " Screen Saver active! At " $ (Date)> $ Log