LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-23-2013, 09:38 AM   #1
project.linux.proj
Member
 
Registered: Dec 2012
Posts: 75

Rep: Reputation: Disabled
script not running with Cron


Hi

I have Centos 6.2, kernel 2.6.32-220.23.1.el6.x86_64 installed. I want to execute the script with user root cron .The script open browser in backend and render some value.
If I am running the script on shell it runs fine but if I run with user root crontab it doesn't run. i am using absolute path in the script but didn't work and defined path for JAVA_HOME, PATH, DISPLAY in script itself but didn't work. what need to be done to execute with crontab. Below is the script and crontab entry.

#!/bin/bash
export DISPLAY=:0.0
export JAVA_HOME=/usr/java/jdk1.7.0
export PATH=/usr/lib64/qt-3.3/bin:/usr/java/jdk1.7.0/bin:/opt/apache-maven-3.0.4/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
/usr/bin/xvfb-run --auto-servernum --server-num=0 /usr/java/jdk1.7.0/bin/java -jar /home/dikshit.rajkhowa/AutoScript/prod6.jar


crontab:
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin
*/1 * * * * /home/dikshit.rajkhowa/AutoScript/sop_alerts.sh

Last edited by project.linux.proj; 07-23-2013 at 09:40 AM.
 
Old 07-23-2013, 09:59 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,836

Rep: Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360
Code:
#!/bin/bash -l
try that in your script... its a lower case L
 
Old 07-23-2013, 10:30 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
What's working shell for root user? Once try like:
Code:
*/1 * * * * 'sh /home/dikshit.rajkhowa/AutoScript/sop_alerts'
OR
*/1 * * * * 'bash /home/dikshit.rajkhowa/AutoScript/sop_alerts'
 
Old 07-23-2013, 10:47 AM   #4
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 979
Blog Entries: 2

Rep: Reputation: 235Reputation: 235Reputation: 235
How are you expecting the cron job to gain access to the X display?
 
Old 07-23-2013, 12:41 PM   #5
project.linux.proj
Member
 
Registered: Dec 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
Shiva.

I tried your way usin -l in the script and set the cronjob like you suggested it didn't work.

linosaurusroot

I mentioned the DISPLAY variable so the xvfb-run should use X display. how is it using mannually on the shell. Actually this is where i am stucking.
 
Old 07-23-2013, 12:44 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Cron doesn't have access to the display unless you are logged in. If you are not logged in, no display, and the program will error out. If someone is logged in other than root, no display, and again the program will error out.

Not a good thing to do with cron.
 
Old 07-23-2013, 01:15 PM   #7
project.linux.proj
Member
 
Registered: Dec 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
jpollard:

Even if i logged in the cron doesn't work .
 
Old 07-23-2013, 01:26 PM   #8
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 2,329
Blog Entries: 1

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Anything X will need the magic-cookie of the user that started X.

~/.Xauthority

And if we're talking about a chroot environmnet it'll need a lot more than that. Still not a good idea to do with cron. It's probably easier to write out a log file and tail -f /the/log/file in a terminal for anyone monitoring the "alerts".
 
Old 07-23-2013, 01:51 PM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by project.linux.proj View Post
jpollard:

Even if i logged in the cron doesn't work .
It can depend on your system... you have to define where the .Xauthority file is located, and that can vary.

The default is ~/.Xauthority, and guided by the environment variable XAUTHORITY.

On some/many systems the file is created per login, and the file name or path changes with each login... and doesn't even need to exist (as in it gets deleted) when you logout.

What are you trying to do in the script?
 
Old 07-23-2013, 03:14 PM   #10
project.linux.proj
Member
 
Registered: Dec 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
Script is opening some url in the browser using command xvfb-run and get some values. In shell it is working but with cron it doesn't
 
Old 07-23-2013, 03:17 PM   #11
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,836

Rep: Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360
Can you provide some log output? How about the cron logs, messages, X11 stuff to start with. Something concrete for us to go on. Heck, throw a -x in your shebang line and let it run so we can see the output in the cron log.
 
Old 07-23-2013, 09:25 PM   #12
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by project.linux.proj View Post
Script is opening some url in the browser using command xvfb-run and get some values. In shell it is working but with cron it doesn't
You will need to provide a log of what is being done. Using the virtual frame buffer should not be an issue as the xvfb-run creates its own authority file.

The problem you are trying to solve must be really strange - virtual frame buffer displays don't output anything.
 
Old 07-24-2013, 04:56 AM   #13
project.linux.proj
Member
 
Registered: Dec 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
I am attaching emails with strace results with cron and manually. Please check the strace results with cron file filename ( running with cron ) and manually with script filename ( running manually ). Please check if the information is sufficient to diagnose.
Attached Files
File Type: txt running with cron.txt (6.9 KB, 26 views)
File Type: txt running mannualy.txt (9.2 KB, 16 views)
 
Old 07-24-2013, 10:26 AM   #14
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
First thing I see: "bad file descriptor" (in and of itself is not necessarily an error), look at the system call I see
Code:
read(3, "#!/bin/bash \r\n/usr/bin/xvfb-run "..., 80) = 80
No error there... but what is that \r doing there? The space preceding it doesn't do anything, but that \r could. Is your script a MSDOS file format??

Other than that, there is nothing really wrong with the trace.

I think you will have to provide the script itself. and a log is usually the output of setting -vx on the interpreter line.
 
1 members found this post helpful.
Old 07-24-2013, 10:32 AM   #15
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,836

Rep: Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360
Jpollard is correct here. OP, try and write that line out by hand. do not copy and paste it. you have an invisible carriage return and newline character from mac/windows creeping in there.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getting error while running script under cron project.linux.proj Linux - Newbie 3 06-27-2013 04:23 PM
[SOLVED] Running scheduled script with cron snadjari Linux - Newbie 5 03-04-2011 03:39 PM
Problem in running a script in CRON senthilvael Linux - Newbie 11 11-21-2007 02:23 PM
cron NOT running php script ??!! hendrixx Linux - Software 2 11-15-2006 08:18 AM
running a 'dcop' script from 'cron' dsunger Linux - Software 0 05-10-2004 02:17 AM


All times are GMT -5. The time now is 09:30 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration