LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Cron won't open console to run script (https://www.linuxquestions.org/questions/linux-general-1/cron-wont-open-console-to-run-script-499828/)

rollo 11-08-2006 02:27 PM

Cron won't open console to run script
 
I am trying to get cron to run a script in a console. The script must run in a console because it requires interaction. Using KCron, I have added the line:

Code:

/usr/bin/konsole -e /home/rollo/scripts/script.sh
to crontab (which one..?), which makes crontab -l produce this:

Code:

rollo@KanotixBox:/var/mail$ crontab -l
#
0 21 * * *      /usr/bin/konsole -e /home/rollo/scripts.script.sh
# This file was written by KCron. Copyright (c) 1999, Gary Meyer
# Although KCron supports most crontab formats, use care when editing.
# Note: Lines beginning with "#\" indicates a disabled task.

The script seems to run at the correct time (judging by the output of ps), but Konsole doesn't open. Which is no use because it's interactive.

Run directly from KCron ("Run it now"), the script works fine and Konsole opens correctly.

What could be going on? Help much appreciated.

unSpawn 11-08-2006 04:03 PM

Probably needs your $DISPLAY variable exported.

rollo 11-09-2006 12:49 PM

Thanks for that.

My cron command now reads:

Code:

40 19 * * *  DISPLAY=0.0; export DISPLAY; /usr/bin/konsole -e /home/rollo/scripts/script.sh
But still Konsole doesn't run.

What am I doing wrong here?..

unSpawn 11-10-2006 07:11 AM

Add the line export DISPLAY=":0.0" inside your script.sh below the bang (!#/bin/someshell) line.

rollo 11-10-2006 12:50 PM

Thanks again.

Adding the export variable line in the script makes no difference. Presumably because by that stage cron has already failed to run /usr/bin/konsole. Reminder of the cron line:

Code:

0 21 * * *      /usr/bin/konsole -e /home/rollo/scripts.script.sh
If I put /usr/bin/konsole at the start of the script, then (with or without the export variable line) cron runs konsole. But I have no idea how to get the script to 1) open konsole, and then 2) run a script within the same konsole. Which is why I wanted to use konsole -e script.

Any ideas where next?:scratch:

rollo 11-10-2006 01:56 PM

Solved
 
Found the solution. To get cron to run the X app Konsole correctly, add the display switch to the command. Like this:

Code:

/usr/bin/konsole -display :0.0 -e /path/to/script
Thanks unSpawn for the pointer.

Rollo


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