I would like to implement a solution to a specific instance of the generic problem wherein idle users tie up resources. I know the user list can be retrieved with
w, the associated PID with
ps, and the final step with
kill. However, I'd like to automate this process for those users who have been idle for over an hour.
The idea is to read the output of w line-by-line, selecting those lines that contain the regular expression
[0-9]m (finding the users with an idle time greater than 1:00m). Then, the TTY associated with the line is extracted and sent to
ps -t, the output of which contains a list of the PIDs to send to
kill -9. I'm simply not sure how to string all this together.
A final caveat: nothing associated with the root user is interpreted.