7

I have lxle (Lubuntu) 12.04 installed and I spent lots of time looking for working solution to make PC shutdown after some period of idle state.

After checking many programs which haven't worked I decided to spend much time of shell script solution run by cronjob

I am stuck on 2 problems here.

  1. xprintidle doesn't give any results (empty string) when it is run by cronjob - no matter in crontab file or shell file in those environments it just give empty string instead of number of milliseconds of idle.

  2. Secondly it seems not simple for me to run my script from crontab for shutdown commend as a root.

Could you give me a link explaining that topic? I know only sudo as a user, but script shouldn't ask for password but just shutdown system.

Michał
  • 111
  • 1
  • 4
  • lxle != lubuntu and maybe OT. – DK Bose Mar 15 '14 at 09:20
  • This page addresses xprintidle issue http://ubuntuforums.org/showthread.php?t=1069602 and use http://askubuntu.com/questions/246455/how-to-give-nopasswd-access-to-multiple-commands-via-sudoers to grant sudo privileges for the user to run shutdown command – clement Mar 15 '14 at 10:16

1 Answers1

6

You need to set the DISPLAY environment variable before calling it, you can try this in the virtual consoles (Ctrl-Alt-F1) since they don't have the DISPLAY variable set, they will act exactly like the cron script will act.

DISPLAY=:0 xprintidle

or

export DISPLAY=:0
xprintidle

either should work.

Diaa Sami
  • 391
  • 3
  • 4
  • 2
    Keep in mind this will change if you have another monitor (larger/better one) made first display (and you later unplug it, when you take your laptop with you). I spent few hours debugging why my script stopped working today... – LAFK says Reinstate Monica Feb 06 '18 at 20:15