LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cron job is not working (https://www.linuxquestions.org/questions/linux-newbie-8/cron-job-is-not-working-624599/)

moagalbm 02-28-2008 05:57 PM

cron job is not working
 
I created the below script to pop-up an xterm window and when I add it to a corn job it is not working although it is working fine when I execute it manually.

Please look at this problem and let me know what is wrong.

Thank you,

#!/bin/sh
/usr/bin/xterm -display lnx1c059:0.0 -fg white -bg DarkSlateBlue -fn 9x15 -T 'BCC Solaris Servers Regression TEST 3' -geometry 50x50+80+100 -n 'SUN_REGRESSION' -e /home/exp_3/operator/TMP_REG.lnx/TMP_REG/all3 &
exit

chrism01 02-28-2008 06:04 PM

Well, it'd be nice to know what you mean by 'not working'. We need details eg error msgs etc.
Having said that, my first guess would be that since cron is designed to run detached ie no terminal, you're prob getting an email (prob in root) saying something like 'invalid cmd' or 'no terminal to connect to' etc.

moagalbm 02-28-2008 06:11 PM

What I mean is that the cron job won't produce the pop-up window and for your information am running other commands in the same cron job and they are working fine exept for this popo-up window (xterm).

sdct989 02-28-2008 07:01 PM

Are you running the cron job as the same user who started the X session that you expect the xterm window to pop up in?

If not, (and maybe even if so, I've never actually tried to do what you're doing) then one of the problems is most likely that the script doesn't know what display to use when launching the xterm session. You can see this in action if you open a terminal, su to a different user than the one who started X, and then run the same command you are trying to run now.

From there you could either try using the same user that you created the X session with to run the cron job, or you could set the DISPLAY environment variable. For more information on that see: http://www.linuxquestions.org/questi...isplay-365193/

If that doesn't help or you already knew all that it would probably help you to redirect stdout and stderr to a file to give you a better clue as to what is happening.

moagalbm 02-28-2008 09:15 PM

I did the redirection and this is what I got:

[operator@lnx1c059 /tmp]$ more sdderr
Xlib: connection to "lnx1c059:0.0" refused by server
Xlib: No protocol specified

xterm Xt error: Can't open display: lnx1c059:0.0
xterm: DISPLAY is not set

Remember that when I run it manually it works fine. Can you please help me out to resolve this display problem.

Thanks,

Farzan Mufti 02-29-2008 03:22 AM

Try to do this in cron
* * * * * echo "Hello"
Does this work?
Whenever I tried this, it would send me an email. I don't think cron supports screen displays. If it does, then may be by using some special technique.

utoddl 02-29-2008 07:05 AM

The following works for me in my crontab:

* * * * * DISPLAY=:0.0 /usr/bin/xterm -fg white -bg DarkSlateBlue -fn 9x15 -T 'BCC Solaris Servers Regression TEST 3'

(This runs every minute, and is rather annoying!) The relevant part here is to set the DISPLAY environment variable before the xterm command.

It looks like you are calling a script instead of starting your xterm directly from cron. That should work fine, too. I think what's confusing you is that your "-display lnx1c059:0.0" is a little too complicated. That's probably being set up by your graphical login manager. Try "-display :0.0", or put "DISPLAY=:0.0" before your script invocation in your crontab entry, like I did above.

Good Luck.

moagalbm 02-29-2008 05:16 PM

I have tested the last solution and it works fine.

I would like to thank you all and special thanks goes to utoddl I really appreciate your help.


All times are GMT -5. The time now is 08:18 PM.