I have a cron job which runs bash.sh file. If I run the file in terminal it works fine. But as I try to run it as cron job something happened there and I cant figure out what. Cron job looks like:
*/5 * * * * bash /home/vlado/custom-scripts/selenium-server/run-selenium-hub-and-nodes.sh 2>> /var/log/cron/selenium-server.log
and run-selenium-hub-and-nodes.sh is here
#!/bin/bash
cd /opt/selenium-server/
# -c returns number of lines in grep result
countHub=$(ps -x | grep -v "grep" | grep "selenium-server" | grep "role hub" -c)
countNodes=$(ps -x | grep -v "grep" | grep "selenium-server" | grep "role node" -c)
# if selenium server HUB is in ps -x result
if [ $countHub -eq 1 ]
then
# if there is NO NODE
if [ $countNodes -eq 0 ]
then
# start two new nodes
java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://173.249.58.30:4444/grid/register/ &
java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://173.249.58.30:4444/grid/register/ &
exit 0
# if there is only ONE NODE
elif [ $countNodes -eq 1 ]
then
# start one new node
java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://173.249.58.30:4444/grid/register/ &
exit 0
fi
else # if there is NO HUB start new hub and two new nodes
# kill all possible hubs and nodes for sure
pkill -9 -f "selenium-server"
# Start new hub
java -jar selenium-server-standalone-3.141.59.jar -role hub &
java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://173.249.58.30:4444/grid/register/ &
java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://173.249.58.30:4444/grid/register/ &
exit 0
fi
I can see in syslog the script is running and try to send an email. I installed postfix because of it, but I am not able to see the message. There is no more info in syslog file. Is there any other log for which collects more informations about cron jobs? After few hours I made a decision to ask the question. Thanks for help.
Simple solution use the full path to java to have it work. As has been mentioned in the comment nothing get carried into the crontab from the users settings. You need to do it all yourself by setting these things manually.