简体   繁体   中英

Shell script wont run in cron as root

I have the following code in my root cron file: PATH=/opt/someApp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 45 12 * * * /home/ben/MetaBackup/metabackup.sh 2>&1 >/dev/null | slacktee.sh -t "Metabase Backup Error" -a "danger" PATH=/opt/someApp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 45 12 * * * /home/ben/MetaBackup/metabackup.sh 2>&1 >/dev/null | slacktee.sh -t "Metabase Backup Error" -a "danger"

slacktee.sh is located in /usr/local/bin and /usr/bin however when i run this metabackup.sh runs ok but slacktee.sh does not. I have tried absolute location for slacktee also but that did not work. The more confusing thing is i put the exact same lines in my user crontab and slacktee works fine. What am i doing wrong? Or is this an issue with slacktee that i need to raise there?

EDIT: slacktee is available here: https://github.com/course-hero/slacktee

You are redirecting stdout and stderr of metabackup.sh to /dev/null , so I think really no output is piped to slacktee.sh and its standard input is empty.

Try removing > /dev/null

I agree with gile !

If there is no output, slacktee won't be able to print anything.

If it's still not working, try to load profile in your command :

45 12 * * * . ~/.profile;/home/ben/MetaBackup/metabackup.sh 2>&1 | slacktee.sh -t "Metabase Backup Error" -a "danger"

Of course, adapt the file depending on if you are on bash or ksh (.profile or .bash_profile)

Do not forget the ". " in front of your .profile file.

Hope it will help.

Most likely, cron is not finding slacktee.sh in its path. You're setting the PATH for the first command, but that setting does not apply to the command after the pipe.

Try using the full path to slacktree :

... | /usr/local/bin/slacktee.sh -t "Metabase Backup Error" -a "danger"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM