Script to log out automatically

Forum rules
Before you post please read this

Script to log out automatically

Postby bloup on Thu Nov 08, 2012 11:01 am

Hey everyone! I think my script will solve your problems. Basically, there is a very simple little program called xprintidle that just prints the idle time of the current user's X session to stdout.

Code: Select all
#!/bin/bash

MAXIDLE = 60000 #Maximum amount of idle time in milliseconds

while [ 1 ]; do
    if [ `xprintidle` -gt $MAXIDLE ]; then
        mate-session-save --force-logout #Whatever program you use to logout.
        break
    fi
    sleep 1
done


And then just make it a startup application.

You can even add a nested if loop, if you want like a warning message or something, like so:

Code: Select all
#!/bin/bash

MAXIDLE = 60000 #Maximum amount of idle time in milliseconds
DELAY = 30 #Amount of warning time you want to give

while [ 1 ]; do
    if [ `xprintidle` -gt $MAXIDLE ]; then
        notify-send "Foo" "Bar" -t `expr $DELAY '*' 1000` #Whatever warning message you want.
        sleep $DELAY
        if [ `xprintidle` -gt $MAXIDLE ]; then
            mate-session-save --force-logout #Whatever program you use to logout.
            break
        fi
    fi
    sleep 1
done


For the warning message, you can get really creative there. You could probably use Zenity if you wanted instead or maybe even you could embed the $DELAY variable in the warning message like "You will be logged out in $DELAY seconds".

Hope that helps you all out! This was one, of many, dead end threads I found, and I figure I can't be the only one who could really find this handy so hopefully I save other people some heartache.
bloup
Level 1
Level 1
 
Posts: 1
Joined: Thu Nov 08, 2012 10:49 am

Linux Mint is funded by ads and donations.
 

Re: Script to log out automatically

Postby xenopeek on Thu Nov 08, 2012 3:02 pm

You replied this post to this topic: viewtopic.php?f=47&t=36022&start=20. The last comment there is over a year old and the topic is over three years old. Please don't reply to support requests older than 6 months, see the forum rules. I think you post would be more at home here :D
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14562
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 3 guests