2

We have a cron script meant to run Salt in our environment along with several other steps, but for some reason it isn't executing it at all.

root@salt:~# cat /etc/cron.hourly/salt-apply.sh 
#!/bin/bash

/bin/cat << EOF | /bin/bash 2>&1 > /var/log/salt-apply.log
    /bin/date
    cd /srv/salt
    /usr/bin/git pull
    /usr/bin/salt '*' saltutil.sync_all
    /usr/bin/salt '*' state.apply
    /bin/date
EOF

root@salt:~# ls -l /etc/cron.hourly/salt-apply.sh 
-rwxr-xr-x 1 root root 199 Feb  7 22:47 /etc/cron.hourly/salt-apply.sh

It doesn't run, no errors are present in /var/log/salt-apply.log, and cron does appear to be running the hourly run-parts:

root@salt:~# grep -i cron.hourly /var/log/syslog | tail -n 5
Feb  7 22:17:01 salt CRON[6941]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb  7 23:17:01 salt CRON[8817]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb  8 00:17:01 salt CRON[10450]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb  8 01:17:01 salt CRON[12104]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb  8 02:17:01 salt CRON[13761]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)

And yes, the script runs fine if you just execute it at a shell prompt.

Any help would the greatly appreciated. Thanks!

Soviero
  • 4,306
  • 7
  • 34
  • 59

2 Answers2

2

Looks like it was a matter of the .sh at the end of the file name. I could swear I've named scripts in /etc/cron.* with a .py or .sh suffix before, so it might be a bug...

In any case:

root@salt:/etc/cron.hourly# ls
salt-apply.sh
root@salt:/etc/cron.hourly# run-parts --report /etc/cron.hourly --list
root@salt:/etc/cron.hourly# mv salt-apply.sh salt-apply
root@salt:/etc/cron.hourly# run-parts --report /etc/cron.hourly --list
/etc/cron.hourly/salt-apply
Soviero
  • 4,306
  • 7
  • 34
  • 59
0

That is likely related to this bug: https://bugs.launchpad.net/ubuntu/+source/debianutils/+bug/38022

Try to name your script without the .sh extension.

toppledwagon
  • 4,215
  • 24
  • 15