I need to run a script when a user logs in and need to run the script every 5 minutes as long as the user is logged in. Script should run within the users security context and should stop running when the user logs out. I manually added crontab lines for different users:
*/5 * * * * whoami >> /tmp/<username>.txt
The script really started running in each users context, but it never stopped running. Even after users logged out, script continued adding lines to the text files in tmp
folder.
Is there any way to run a script every 5 minutes in logged in users context until logging out?
whoami
withusers | grep -q "\b$USER\b" && whoami