Script not working in crontab

خرید بک لینک

Chances are you need to set the full path for binaries like screen since when the cron job runs, it will not have the $PATH values set the same way you as a user have those set when you login via Terminal or SSH. This answer on Stack Overflow is a decent explanation of the whole deal.

So I would recommend you change your script from this:

screen -A -m -d -S minecraftserver /home/minecraft/scripts/startServer.sh

To this:

/path/to/screen -A -m -d -S minecraftserver /home/minecraft/scripts/startServer.sh

And replace /path/to/screen with the actual full path which you can easily obtain using which like this:

which screen

The output would be something like:

/usr/bin/screen

Or, you could set the $PATH by actually placing it in your script like this:

PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Of course that should match your actual PATH value on your system which you can get by typing in the following:

echo $PATH

But I personally prefer the fullpath method since it’s cleaner to me and $PATH values often change so you don’t want to have a wish-mash of values in your Bash scripts.

PS: Also, a small thing but your Bash script should have the actual Bash interpretter value set in the “shebang” at the top like this so your script would look something like this:

#!/bin/bash
/path/to/screen -A -m -d -S minecraftserver /home/minecraft/scripts/startServer.sh

Of course that /bin/bash should match your systems actual Bash path by running which bash but I doubt it would not be in the /bin/bash path on a mode install.

Recent Questions...

ما را در سایت Recent Questions دنبال می‌کنید

برچسب: نویسنده: استخدام کار بازدید: 198 تاريخ: سه شنبه 1 تير 1395 ساعت: 5:26

صفحه بندی