0

First post on this forum here :) I already saw this on the forum, but it if the crontab starts the script it gives out an error. (It works standalone.)

See this is my script. This is the Log.

And here is my crontab:

* * * * * /bin/bash /home/steam/arma3/restart.sh >> /home/steam/arma3/logs/checkonserv.log 2>&1

The "cannot found error" were fixed, but the execution of the arma3server file doesnt work.

Marc Ma
  • 101
  • 1
    And what error do you get ? – Soren A Dec 02 '16 at 12:30
  • When i start with the crontab the "arma3server" file wont start.. That is the error ^^. So the same problem i saw on the forum. What i did wrong there?? – Marc Ma Dec 02 '16 at 12:37
  • So it's line 62 ? I will guess that you are not in the correct directory. When running from crontab, you are not automatically in your homedir. – Soren A Dec 02 '16 at 12:48
  • Well then how would my start line need to look like? – Marc Ma Dec 02 '16 at 13:23
  • i tested it with ./home/steam/arma3/arma3server but it gives out /home/steam/arma3/restart.sh: 42: /home/steam/arma3/restart.sh: cannot open =: No such file /home/steam/arma3/restart.sh: 42: /home/steam/arma3/restart.sh: 5: not found and if i start it via console / ssh, it just starts like normal (changed it back again to ./arma3server) – Marc Ma Dec 02 '16 at 13:24
  • 1
    I'm not sure how line 41 or 42 can lead to that error message. Could you please run the script with the -x option (e. g. with set -x somewhere near the beginning of the script) and [edit] your question to include the new program output? Also, just to be sure, could you please add a she-bang with an explicit shell interpreter at the beginning of the script file (i. e. #!/bin/bash)? The script contains some Bash-isms that (Da)sh doesn't understand and mistakes for other stuff. – David Foerster Dec 02 '16 at 13:26
  • after i added set -x to line 2 and in the first line #!/bin/bash it gave me all the commands in the file out. – Marc Ma Dec 02 '16 at 14:17
  • 1
    THen we need to see that output, please. – Soren A Dec 02 '16 at 20:27
  • … and did the program do what you wanted? The listing of all encountered commands as the shell understands them is just a way to help understand what it's doing. – David Foerster Dec 03 '16 at 17:26

3 Answers3

0

Very often a script such as this experiences a bash vs. sh invocation issue. In short, crontab defaults to what is explicit in the file as:

SHELL=/bin/sh

while your shell is likely running a bash invocation.

I would recommend:

  1. Adding a #!/bin/bash to the top of your script (if that is the SHELL of choice)
  2. Explicitly adding the /bin/bash to the crontab line such that:

    * * * * * /bin/bash /home/steam/arma3/restart.sh >> /home/steam/arma3/logs/crontabcheck 2>&

If errors persist, please provide an update.

Mark
  • 1,502
  • I updated my post, did not work @ all – Marc Ma Dec 02 '16 at 18:58
  • We'll need to see the new output after the changing and using set -x as recommended. – Mark Dec 02 '16 at 19:23
  • The Output did not change... I tried to set +x on the first line and on the second line: http://pastebin.com/BJuJBNCH – Marc Ma Dec 02 '16 at 19:44
  • A bit hard to help in this fragmented way. First, move #!/bin/bash to the top of the script. Second, recommend install https://asciinema.org/ and record your terminal output so we can see it by executing the script in a terminal. – Mark Dec 02 '16 at 20:25
  • http://89.163.206.189/crontab/ First file shows the execution and second file shows the restart script – Marc Ma Dec 03 '16 at 08:34
  • Parsing those Unicode uploads isn't convenient. One thing I did notice was there may be a problem with your radix calls. You use if (( 5 <= 10#$H && 10#$H < 9 )) . Try assign that to a variable outside the if like (( curRDX=(10#$H) )) then check with if (( curRDX >= 5 && curRDX < 9 )) – Mark Dec 03 '16 at 13:36
  • This part is working ALL things are working, but the execution wont work: – Marc Ma Dec 03 '16 at 13:55
  • This: ./arma3server -par=arma3server_startup_parameters.txt > $logdir/$armalog1 2> $logdir/$armalog2 & – Marc Ma Dec 03 '16 at 13:55
  • [sic] "This part is working ALL things are working, but the execution wont work" - not at all helpful. If you are so convinced that your problem lies solely at that line, then your problem is not with your script but with your arma3server element. – Mark Dec 03 '16 at 14:09
  • The Problem is that the execution of the arma3server element is starting just like normal when i execute the script by hand. – Marc Ma Dec 03 '16 at 14:36
0

Ok, so i found a workaround about this:

  • Put your script in an infinite Loop
  • Wait for 1 min @ the end in the script (sleep 1m)
  • Execute the script with screen
Marc Ma
  • 101
0

Never assume that cron will work the same as running something manually. If you ever expect to run your script in cron, make sure your script sets up it's environment exactly as needed, and uses full paths to the commands you want to run.

Spaldam
  • 21