LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-08-2015, 01:10 PM   #1
heathcliffz
LQ Newbie
 
Registered: Jul 2007
Location: Brazil
Distribution: Ubuntu
Posts: 13

Rep: Reputation: 0
Unhappy Cron job shut down the system ignoring the specified time


hi guys,

I made a script that asks the user if he wants to shut down the computer in 10 minutes or wait another hour and I scheduled in cron to run each hour from 18h to 7 am. However it happened two problems:
1 - The box that asks the question does not appear
2 - It does not turn off in 10 minutes but at the time that runs the script as if I had used the now option

ideas?

The Script:
Code:
#!/bin/bash
date=`date`
usuario=`who | sed q | awk -F" " '{print $1}'`
export XAUTHORITY=/home/$usuario/.Xauthority
if zenity --question --text="Seu micro ser desligado em 10 minutos. Tudo bem?" --title="Desligar?" --ok-label="Prorrogar" --cancel-label="Pode Desligar" --timeout=300; then
  echo "NAO DESLIGOU "$date >> /tmp/testes_desligar;
else
  echo "DESLIGOU "$date >> /tmp/testes_desligar;
  /sbin/shutdown -h +10; #already tried shutdown -h 10 but same thing happens...
fi
The CRON job (on /etc/crontab):
Code:
48 0-7,16-23 * * * root /home/myuser/shell/desliga.sh
 
Old 12-08-2015, 01:28 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
The cron job has no DISPLAY variable set in the environment, so the zenity process always fails. There should have been a "(zenity:nnnn): Gtk-WARNING **: cannot open display:" message written to stderr and sent to you in email.
 
Old 12-08-2015, 02:32 PM   #3
heathcliffz
LQ Newbie
 
Registered: Jul 2007
Location: Brazil
Distribution: Ubuntu
Posts: 13

Original Poster
Rep: Reputation: 0
If zenity will not work in this case, how can I make a warning to the user?
 
Old 12-08-2015, 02:42 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Try adding the following to the beginning of your script:
export DISPLAY=":0.0"
 
  


Reply

Tags
cron, shutdown, zenity



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] AWS EC2 CRON Job timestamps are not System Time tuntsfaah Linux - Server 1 12-11-2014 06:21 PM
Cron Job: Start it Only once on specified time jCash Linux - Newbie 2 12-07-2007 07:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration