My crontab:

* * * * * ~/d2gs.sh

My application:


# D2GS

# Go to the directory
cd ~

# Run the applications
if ! ps aux | pgrep "D2GS"; then
    wine "C:/D2GS/D2GS.exe" > /dev/null 2>&1 &

The crontab is not starting the process. Which is weird, since I can run ~/d2gs.sh successfully manually.

  • 3
    What does the generated mail message say? – Ignacio Vazquez-Abrams Nov 29 '17 at 20:37
  • 4
    cron does not set any of your environment variables. Probably relevant: serverfault.com/questions/449651/… – Andrew Henle Nov 29 '17 at 20:40
  • 4
    This is your second question about the same script. What is the actual problem you're trying to solve with it? – DopeGhoti Nov 29 '17 at 20:55
  • @DopeGhoti I want to thank you for the reply in the first question - the > /dev/null 2>&1 & worked. But now, the crontab doesn't fire the d2gs.sh. I can start it only using the terminal. Crontab doesn't start it... – htorbov Nov 29 '17 at 21:05
  • What is your D2GS.exe program really doing? Why are you using Linux to start a Windows program? – Basile Starynkevitch Nov 29 '17 at 22:54

You have to distinguish between "the crontab is not starting the process" and "the process does start but does not do what it is supposed to". And make sure the file is executable.

In contrast to what I assumed the usage of ~ in crontab is not a problem. The whole command string is passed to a shell.

  • I am not sure that /bin/sh is required to expand ~ even if some implementations of it could understand that expansion. – Basile Starynkevitch Nov 29 '17 at 23:10
  • With the full path or not, it still doesn't start. I've saw somewhere, that I need to specify export DISPLAY=:0, but I don't have X-server on my server. – htorbov Dec 2 '17 at 19:49
  • @htorbov You may need an X Window virtual framebuffer (Xvfb) – Hauke Laging Dec 2 '17 at 20:32

The cd ~ might not work (since tilde expansion is not universal). Prefer cd $HOME to it (which is guaranteed to do the same for all implementations of /bin/sh ...) ..... Remember that POSIX sh (or /bin/sh) is generally not bash (and your /bin/sh might not be fully POSIX compliant, but more "bourne"-like)!

Of course, you could add something like pwd > /dev/stderr in your script (for debugging purposes).

wine generally needs an X11 server to display windows. And a program started from cron generally don't any X11 server or terminal. So wine is probably failing to start (from your cron job). You might need to set some DISPLAY variable for Xlib. But you might use Xvfb, see here.

At last, pgrep(1) is scanning processes. Either use ps aux | grep "D2GS" or learn how to use pgrep alone.

I recommend using echo something > /dev/stderr or better echo or printf(1) (with a suitable redirection) or logger(1) in your script, at least for debugging purposes (in several places).

And I won't redirect wine-s stderr and stdout to /dev/null at least during the debugging phase. Can't you code (at least temporarily during debugging) wine "C:/D2GS/D2GS.exe" >> /tmp/wine.out 2>&1 and look into /tmp/wine.out with some pager like less ?

Your cron (and your shell script) is not using your interactive PATH variable. You should consider setting it explicitly in your script (or crontab). See environ(7).

  • The first part makes no sense. The question says that the script works when called manually. Also, it's easy enough to test that ~ does work in a sh script. – Sparhawk Nov 29 '17 at 23:02
  • I am not sure that the OP's shell is working like cron. It probably does not. And cd $HOME is certainly more sh friendly than cd ~ (which is probably a bashism) – Basile Starynkevitch Nov 29 '17 at 23:03
  • With the full path or not, it still doesn't start. I've saw somewhere, that I need to specify export DISPLAY=:0, but I don't have X-server on my server. – htorbov Dec 2 '17 at 19:49
  • Then you cannot use wine for D2GS.exe; BTW the X11 server might run on some other machine (and screen). But you probably need one. – Basile Starynkevitch Dec 2 '17 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.