0

So my ultimate goal is to have a shutdown script that prompts me before shutdown in the terminal. The normal message parameter for the /sbin/shutdown doesn't seem to force a terminal to appear, and I want a terminal to pop up every time.

So, I've been trying to get a terminal to appear with cronjobs, with no success. I've searched every post I can find on this website and others, tried so many different things, and I still end up stuck.

So, here are my scripts. They're both pretty simple, as I'm just trying to get the terminal display thing working before I try actually doing something more complex.

test.sh: This script tries to open gnome-terminal after being called by the cronjob to run the second script.

#!/bin/bash
gnome-terminal -e /home/craig/Documents/Scripts/test2.sh

test2.sh: This is just a simple script that outputs some text and waits for the user response.

#!/bin/bash
echo "Submit your response:"
read -t 10 -p "";
echo "Your reponse was: $REPLY"
read -t 10;

Both scripts work if I run them directly from the terminal. test.sh opens another terminal window and runs test2.sh, for example. But I can't get them to work in cron.

I've tried my local cron (crontab -e) and the root cron (sudo crontab -e), with no success. I've tried setting the DISPLAY variable, messing with XAUTHORITY, anything I've seen referenced. I can never get it to work.

Here are some of the non-working cronjobs that I have in my crontab:

 52 18 * * * env DISPLAY=:0.0 | xhost +local | /usr/bin/gnome-terminal -e /home/craig/Documents/Scripts/test2.sh
56 18 * * * /usr/bin/gnome-terminal --display=:0.0 -e /home/craig/Documents/Scripts/test2.sh
24 23 * * * export DISPLAY=:0 && /home/craig/Documents/Scripts/test.sh

I know that xhost frees up the terminal, but I get the impression that is less secure. Also, I don't know if it makes a permanent change or not, I want this to be uber flexible (ie, I don't want to have to run xhost every day so that it runs. I've tried running xhost from within my script, didn't help).

Anyway, Most of the time I get a "No protocol specified" error message, that says "Unable to init server: Could not connect: Connection refused Failed to parse arguments: Cannot open display:" Depending on how I set up the DISPLAY variable, that last part frequently has the ":0" for the display in it.

I'm just totally lost at this point. Please help. Thanks.

craigmiller160
  • 5,751
  • 9
  • 41
  • 75

0 Answers0