0

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:

#!/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):

48 0-7,16-23 * * * root /home/myuser/shell/desliga.sh
6

1 Answer 1

0

Between the two issues, you may need to:

For 1) edit the sudoers file (use 'visudo') if some part of your script requires root access. Lots of info on the web on how to do this.

For 2) this sounds like a script debugging issue. Do you get the same behavior if you run the script from the terminal rather than waiting for cron to kick it off? Is the behavior different if you run it as root (sudo)?

You might also consider adding [[ and ]] to your if statement. +1 to @Elder Geek for case.

3
  • when I run the script on terminal it works perfectly as root or with sudo and a normal user...
    – Heathz
    Dec 8, 2015 at 20:27
  • So is this in your crontab? or in the root user's crontab? I.e. when you added the cron line via crontab -e were you logged in as your username or as root? I'm thinking if you did sudo crontab -e it may have put it under the root user's crontab, but I am not 100% sure.
    – tniles
    Dec 8, 2015 at 22:54
  • I confirmed it: if you do sudo crontab -e it will place it in the root user's crontab, which I think is what you want.
    – tniles
    Dec 8, 2015 at 23:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .