0

I am trying to run a sh script using cron. This script requires a display.

I have tried:

# Xvfb display
/usr/bin/Xvfb :10 -ac -screen 0 1024x768x24 &
41 18 * * * /bin/sh /path/to/script/script.sh > /path/to/log/log.log 2>&1

Nothing happened and the log.log was not created.

Second try:

43 18 * * * <user> export DISPLAY=:10 /bin/sh /path/to/script/script.sh > /path/to/log/log.log 2>&1

Same result no log file.

(ubuntu) CMD (export DISPLAY=:10 /bin/sh /ibc.paper/twsstart.sh > /crontry.log 2>&1) Jun 14 18:43:01 CRON[1809]: (CRON) info (No MTA installed, discarding output)

I have been trying all the things I could think of but nothing works.

Can someone tell me what to check?

Sid
  • 3,749
  • 7
  • 29
  • 62
  • Where and how are you starting the Xvfb server? – tripleee Jun 14 '21 at 19:16
  • @tripleee I am using command line to start the Xvfb server before the `cron` time. Is this supposed to be done in the script or execute it in cron? Most concerned about why it won't send the output to log.log file. – Sid Jun 14 '21 at 19:22
  • It seems upset that you don't have a *"Mail Transfer Agent"* set up. Have you maybe got an Email address in your crontab? – Mark Setchell Jun 14 '21 at 21:19
  • @MarkSatchell No, that means there is no MTA installed, `cron` *always* tries to send mail if there is an error with redirection. This and many more common problems is included in https://stackoverflow.com/questions/22743548/cronjob-not-running which the OP should consult for troubleshooting. – tripleee Jun 15 '21 at 04:15
  • You apparently don't have write access to the log file. You want to fix that. Maybe that's even sufficient for solving this. – tripleee Jun 15 '21 at 04:17
  • As which user do you start the server, and how do you arrange to make sure it's running when `cron` needs it? It probably doesn't matter much if this happens in the same script, though that would be a simple way to be sure it's running, and lets you shut it down afterwards when it's not needed. – tripleee Jun 15 '21 at 04:20
  • @tripleee I just check whether the user `ubuntu` has permission to write to the file. I went into the logs folder edited a file using nano and saved without an issue. I start the display using user: `ubuntu`. I used an `echo $DISPLAY` to check whether the display is running. Output: `localhost:10.0` – Sid Jun 15 '21 at 04:24
  • The only explanation I can think of for the `cron` job to fail and want to send mail to you when you redirect all output to a log file is that it cannot write to that log file. It would seem weird to have the log file in the root directory, and unlikely that you have actually granted your regular user write access there. – tripleee Jun 15 '21 at 04:59

0 Answers0