2

My os is Ubuntu 12.04

I am trying to execute a shell script from cron tab ..

that shell script works fine .. when i am executing directly in command line .. like

sh out.sh

it works fine .. but when i am set cron for this shell script its not working

my shell script : out.sh:

#!/bin/bash
firefox "http://localhost/acceptance/selenium-main/shell.php"

it will opens that shell.php webpage in firefox browser ... its works fine when executing directly from CLI

..i an setting cron job like this

sudo crontab -e

then

23 13 * * * bash /usr/share/nginx/www/acceptance/selenium-main/out.sh

this was not working ..

i even tried

33 13 * * * /usr/share/nginx/www/acceptance/selenium-main/out.sh

this was also not working ..

even i tired executing from bin also : /usr/local/bin/out.sh

none of the methods are working

Please suggest how to fix this .. because crontab not executing shell scripts ..

5 Answers 5

2

Try to use absolute path:

23 13 * * * /bin/bash /usr/share/nginx/www/acceptance/selenium-main/out.sh

Also try to run bash in login mode if something doesn't work right.

23 13 * * * /bin/bash -l /usr/share/nginx/www/acceptance/selenium-main/out.sh

That would try to fix other variables like PATH. If not, try to explicitly set it in your script, or just use absolute paths everywhere.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the suggestion .. i tried all the methods .. but nothing works for me .. even i tried in other system in my work station .. its not working ...
i tried VoidPointer solution which is working for me now
0

It looks like the behaviour of cron when configuring GUI applications. Try creating a wrapper script like,

wrapper_script:

export DISPLAY=:0.0
xhost + 2>>/tmp/err.log
firefox "http://localhost/acceptance/selenium-main/shell.php" 2>>/tmp/err.log

Add cron entry as,

33 13 * * * bash /path/to/wrapper_script.sh

8 Comments

Thanks for the suggestion .. i tried all the methods .. but nothing works for me .. even i tried in other system in my work station .. its not working for me ..
@user2728390 Did you execute wrapper script and check manually? If so, what is the error? Are you trying over SSH? if so, it has different procedure.
no SSH .. i am just using Ubuntu desktop ... Here is output when i manual enter in terminal : adi@zest-System-Product-Name:/usr/share/nginx/www/acceptance/selenium-main$ sh out.sh access control disabled, clients can connect from any host .. but when executing manually ... script working well .. i dont know why cron is not working
As given in updated answer, redirect the error to /tmp/err.log and provide the log when run using cron. Also when opening the terminal on Ubuntu Desktop, what is the value of echo $DISPLAY?
You are looking like Programming scientist ... Really great .. its Now working for me .. Thank you so much .. I have a doubt ..My shell script will execute a php file in firefox .. this php will generate a report .. it it possible to close this firefox window .. after this php file execution ...
|
0

try the same solution konsolebox added to the firefox line in your shell script. maybe firefox is not in your path

Comments

0

How about

php /path_to_localhost/acceptance/selenium-main/shell.php

If it is just producing a report and has no user interations, just run the script. You do not need a browser to run php scripts.

Comments

0

The big difference between running something in cron and from the command line is that your profile is run for your shell, so all the environment variables needed by your script are set correctly, but cron uses a naked "profile-less" shell.

Try using a script that sets all the environment variables it needs before executing the whatever the script does, so its "self contained".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.