Search code examples
bashshellscriptingcron-task

Script not working with crontab but working when launching it normally


this is my first question on SO, otherwise I generally find what I need.

So here we go, here is my script :

#!/bin/bash
cd /home/laxa/Teeworlds_servers/scripts
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
kill `ps aux | grep -v "grep" | grep "/home/laxa/Teeworlds_servers/" | awk ' { print $2 } '`

and here is my crontab test :

48 23 * * * /home/laxa/Teeworlds_servers/scripts/restart_server.sh > /home/laxa/log.txt 2>&1

So, when I use the script in a bash shell with putty, the script gets executed fine and does it's job. But when it's executed by the crontab, after some debug, it fails on the kill command. I tried to set manually the PATH cause it was a big wrong. Another friend told me to try to debug it, but apparently the script dies directly.

So I am quite blocked now, if someone has an idea or a solution, I would really welcome it. Thanks.


Solution

  • Ok so, finally I founded that my line was working, but she was returning more processes than intended. And then I discovered that the script was killing himself, so thanks guys !