Search code examples
macoscron

cronjob not executing on macos


This should run once a day at 1 am:

0 1 * * * pod repo update | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /Users/ci/podRepoUpdate.log 2>&1

however the log (/Users/ci/podRepoUpdate.log) stays empty.

If I run the command

pod repo update | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /Users/ci/podRepoUpdate.log 2>&1

manually, it works. What am I missing here?


Solution

  • Putting the command in an shell script worked, as suggested by Gordon Davidsson. This is my crontab now:

    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    0 1 * * * /Users/ci/podRepoUpdate.sh
    

    The shell script:

    #!/bin/sh -e
    
    pod repo update | ts '[%Y-%m-%d %H:%M:%S]' >> /Users/ci/podRepoUpdate.log 2>&1