The following is a script to calculate the idle time of a machine. The script is supposed to check xserver idle time at a time interval of 1 minutes and log the result to a location via cronjob. But that is not working as i expected. It is not reporting the idle time even if the machine idles for more than the idle time limit assigned.
The time limit in the example is 1 minute. It is just a dummy time set for asking this question and checking without wasting time.
Can anybody help ?
#!/bin/bash
timeinmsec="$(xprintidle)"
timeinmin="$(($timeinmsec / 60000))"
if [[ "$timeinmin" -gt 1 ]]
then
echo "$timeinmin Minutes idle time reported" >> /home/user/log.txt;
echo $(date '+%X') >> /home/user/log.txt;
echo "$line" >> /home/user/log.txt;
else
echo "No idle time reported" >> /home/user/log.txt;
echo $(date '+%X') >> /home/user/log.txt;
echo "$line" >> /home/user/log.txt;
fi
Output i get
No idle time reported
05:24:01 PM
No idle time reported
05:25:01 PM
No idle time reported
05:26:01 PM
No idle time reported
05:27:01 PM
echo $timeminsec
? Or that the process, running from crontab, don't have an active xserver session?