'Idle message + counter in linux

I would like to write a bash script that is a "watcher program", which means, that it is running in the background and verifies certain stuff.

My program should check for a list of users (given in a textfile, the textile's name is given as a parameter), and if the users are idle for more than 1 minute, it should send them a message with the number of minutes they have been idle for.

Example:

User asdf has been idle for 1 min:

message: You have been idle for 1 min

User asdf continues being idle, 2 minutes pass:

message: You have been idle for 2 min

... User asdf has been idle for n minutes:

message: You have been idle for n min

Users that are not online, but listed in the textfile should not be considered at all.

How should I do this process? How do I check if a user is idle? how do I write them a message only once? (not everytime the loop starts again)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source