mutt in shell script not working crontab

Need help with C, C++, perl, python, etc?

mutt in shell script not working crontab

Postby Sophjer » 2017-01-26 14:48

I've got a shell script that needs to be automated via crontab. I've tested the script by running it manually and it works as intended.
I have also confirmed that the script runs from the crontab entry, but there is one line in the script that doesn't work, where I use mutt to send me a notification.
The script still works but the following command doesn't
Code: Select all
mutt -s "Alert about the website" -a log/$LOGFILE.txt temp/index.html -- myemail@mycompany.ca < message.txt


I've also tried adding the output of
Code: Select all
echo $PATH

Code: Select all
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

to the top of the cron file when I edit it with
Code: Select all
crontab -e


but get:
Code: Select all
errors in crontab file, can't install.
Do you want to retry the same edit? (y/n)


Basically I'm writing a script that will alert me of any changes on one of our sites using curl, diff and mutt.
Thanks
Sophjer
 
Posts: 7
Joined: 2016-03-27 21:56

Re: mutt in shell script not working crontab

Postby wizard10000 » 2017-01-26 15:02

You need full paths. crontab doesn't inherit a user's environment and so a path edit would be useless :)

Code: Select all
/usr/bin/mutt -s "Alert about the website" -a log/$LOGFILE.txt temp/index.html -- myemail@mycompany.ca < message.txt
we see things not as they are, but as we are.
-- anais nin
User avatar
wizard10000
 
Posts: 1204
Joined: 2011-05-09 20:02
Location: everywhere i go, there i am!

Re: mutt in shell script not working crontab

Postby Sophjer » 2017-01-30 17:10

Thanks wizard10000 that's exactly what I ended up doing.
Now it works.
I thought I had read elsewhere someone explained how to set your path in the crontab entry somehow.
I think I need to teach myself python and I could probably make this thing do the job even better.

Thanks for your help.
Sophjer
 
Posts: 7
Joined: 2016-03-27 21:56

Re: mutt in shell script not working crontab

Postby grumpy_geek » 2017-01-31 08:22

Sophjer wrote:how to set your path in the crontab entry


Code: Select all
# user-level crontab

# be explicit
PATH=/usr/bin
# not required
SHELL=/bin/bash

* * * * * xterm -display :0 -hold -e "echo $PATH; echo $SHELL"

# [ file ends here ]
User avatar
grumpy_geek
 
Posts: 22
Joined: 2017-01-20 16:03

Re: mutt in shell script not working crontab

Postby Sophjer » 2017-02-14 16:26

Thanks for that, will try soon.
Have now moved onto other wild & crazy projects
Sophjer
 
Posts: 7
Joined: 2016-03-27 21:56


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable