mr_pool_404
mr_pool_404

Reputation: 498

Crontab not recognising command

I have a bash script which I want to run as a cron job. It works fine except one command. I redirected its stderr to get the error and found out that the error it shows was the command not recognized. It is a root crontab. Both the current user and root execute the command successfully when I type it in the terminal. Even the script executes the command when I run it through the terminal.

Startup script :

#!/bin/bash
sudo macchanger -r enp2s0 > /dev/null
sudo /home/deadpool/.logkeys/logger.sh > /dev/null

logger.sh :

#!/bin/bash
dat="$(date)"
echo " " >> /home/deadpool/.logkeys/globallog.log 
echo $dat >> /home/deadpool/.logkeys/globallog.log
echo " " >> /home/deadpool/.logkeys/globallog.log
cat /home/deadpool/.logkeys/logfile.log >> /home/deadpool/.logkeys/globallog.log
cat /dev/null > /home/deadpool/.logkeys/logfile.log
cat /dev/null > /home/deadpool/.logkeys/error.log
logkeys --start --output /home/deadpool/.logkeys/logfile.log 2> /home/deadpool/.logkeys/error.log

error.log

/home/deadpool/.logkeys/logger.sh: line 10: logkeys: command not found

Upvotes: 0

Views: 1705

Answers (1)

Brandon Miller
Brandon Miller

Reputation: 5065

Remember cron runs with a different environment then your user account or root does and might not include the path to logkeys in its PATH. You should try the absolute path for logkeys (find it with which logkeys from your user) in your script. Additionally I recommend looking at this answer on serverfault about running scripts like they are running from cron when you need to find out why it's working for you and not in a job.

Upvotes: 2

Related Questions