osx - How do I pipe only certain results from a command to another or an If statement? -
i trying find way build cron job log out idle users in osx based on last time actively moved mouse. osx's built in functionality logs out , if entire machine idle. way have been able find out idle using 'w' gives me few columns , 1 has idle time in it. how can pipe numbers field , ignore rest? there easier way it?
how write this:
1.issue command w
2.check username see if time idle greater 30 mins , if issue command ps -ajc | grep loginwindow , find username , pid loginwindow user exceeded idle time , issue sudo kill -9 "whatever pid user's login window"
and exclude "whateverusernamehere" script (so way stay logged in).
i know asked pipes. standard way is: consider using tmout variable.
add login profile:
declare -r tmout=14400
this logs out inactive interactive users after 14400 seconds, 4 hours of inactivity.
you solution, kill -9, kind of harsh , can cause problems. user can have file open, method not detect that, , kill user off, can corrupt file.
Comments
Post a Comment