Simple Bash Script - Crontab

I've put together a very simple bash script to check for software patches and bounce the server, once complete. This is on a Mac server. The script works just fine upon execution, however, cron responds with:

/bin/sh: /usr/local/bin/softwareupdates.sh: No such file or directory

Crontab:

#*      *     *    *     2,3,7    /usr/local/bin/softwareupdates.sh

Here's my simple bash script:

The script lives in /usr/local/bin. It's obvious to me, environment is the issue. However, not sure the direction to resolve. Attempted a variety of options. Any assistance, is appreciated.

What's the name of the script? Its permissions? Pls show the result of ls -l /usr/local/bin/soft* .

I made a simple mistake in crontab. I added an "s," to the name. It's singular, "softwareupdate.sh." I've made the correction and now receive output:

/bin/sh: softwareupdate.sh: command not found

To add, it's in "roots" crontab. I execute from root, manually, with no issues.

Permissions:

-rwxr-xr-x@ 1 admin  staff  142 Oct  1 12:38 /usr/local/bin/softwareupdate.sh

There (shebang) might be carriage returns, try

tr -d '\r'  < /usr/local/bin/softwareupdates.sh   > script_tmp
mv script_tmp /usr/local/bin/softwareupdates.sh && chmod +x /usr/local/bin/softwareupdates.sh

Resolved. Need to specify "softwareupdate" command, path.

#!/bin/bash
PATH=$PATH:/bin:/usr/local/bin

#Checks and executes software updates & bounces server. 

sudo /usr/sbin/softwareupdate -i -a

sudo reboot

When the cron job is owned by root, do you still need to use 'sudo'?

Puzzled. :slight_smile:

For a root crontab you don't need sudo.
But you should fix the execution time, otherwise it will update/reboot every minute!
For example

# update/reboot at noon
0  12     *    *     2,3,7    /usr/local/bin/softwareupdates.sh