Search code examples
macosshellterminalcronadb

Adb path not found while running cron


I am trying to run some adb commands using cron. While running cron, I expect it to run under a default shell environment and not the user's which is why I provide the path of adb file to be appended in the PATH while setting up cron as follows. However as you can see from the output, cron fails to find adb.

Command I use to set crontab

sudo crontab -u mcj -e

Crontab

cron_script.sh

#!/usr/bin/env bash

export PATH=$PATH:/usr/local/bin/adb
export PATH=$PATH:/Users/mcj/bin/darwin/adb
adb_path="$(which adb)"
echo "adb path: "$adb_path
echo "path: "$PATH
echo "home: "$HOME

Output

adb path: 
path: /usr/bin:/bin:/usr/local/bin/adb:/Users/mcj/bin/darwin/adb
home: /Users/mcj

If I use a terminal and try to run which adb as follows, it does find the adb path

Milin'sMacBook:~ mcj$ which adb
/usr/local/bin/adb

Solution

  • According to your 'which' output, the adb command is a file in the /usr/local/bin directory. The $PATH variable requires directories, not the actual executables.

    In short, your PATH should be:

    export PATH=$PATH:/usr/local/bin