PDA

View Full Version : mail and cron in the terminal




NewbieNerd
Mar 8, 2006, 02:10 PM
I'm doing some Unix homework, and part of the assignment is to use cron to mail something in, but this doesn't seem to be working. I try

echo "message" | mail -s "subject" *my email address*

and it tells me I have mail in /var/mail/craigbowles, where I look and see it's error messages about not being able to deliver my mail. What's up with that?!


For cron itself, shouldn't I just be able to create a file that includes

45 14 8 3 * echo "cron worked"

to display the message to the screen today at 2:45 in the afternoon? It doesn't work though. What's up with this? Thanks.



NewbieNerd
Mar 8, 2006, 02:14 PM
I forgot to mention, yes I do enter

crontab *filename*

and it appears in my user crontab file, but still doesn't work.

plinden
Mar 8, 2006, 02:22 PM
I forgot to mention, yes I do enter

crontab *filename*

and it appears in my user crontab file, but still doesn't work.
What do you see using "crontab -l"?

Doctor Q
Mar 8, 2006, 02:27 PM
I can explain why you didn't get the "cron worked" message. cron tasks are run in the background at the specified time(s). So there is no screen/terminal/window for the "cron worked" message to echo to. cron will e-mail you (the owner of the crontab file) any output from the command(s) it runs. If that's good enough, fine.

If you want cron to do other than email you the output of some commands, you need to give it commands that take care of their own output. For example, the command echo "cron worked" >/some/file/somewhere would put the message in the specified file.

Perhaps another member can identify a simple command you could use in a cron task to open a window and display a message. I think that's what you need for what you have in mind.

jeremy.king
Mar 8, 2006, 02:28 PM
I too had the same issue when trying to pipe the echo into the mail command. Then I tried to use


mail -s "subject" my@email.address
some text
[Control-D]



and it sent it fine, albeit to my spam folder.

As for your cron issue, you aren't going to see echo statements in terminal. I would suggest redirecting to a file.

* * * * * echo "cron worked" >> /tmp/cronlog

jeremy.king
Mar 8, 2006, 02:46 PM
found a command that can "notify" you that cron worked. Courtesy of ADC (http://developer.apple.com/documentation/Darwin/Reference/ManPages/index.html#//apple_ref/doc/framework/manpages)

* * * * * echo "cron worked" | write <loginname>

where loginname is your short name.

NewbieNerd
Mar 8, 2006, 03:42 PM
found a command that can "notify" you that cron worked. Courtesy of ADC (http://developer.apple.com/documentation/Darwin/Reference/ManPages/index.html#//apple_ref/doc/framework/manpages)

* * * * * echo "cron worked" | write <loginname>

where loginname is your short name.

Hey, thanks that worked, so now at least I know that cron does indeed work. As for the mail, your doing


mail -s "subject" *emailaddress*
type type type
[Control D]


didn't seem to work for me either. I still ended up getting a message a little later saying that there was an error sending it. hmm

NewbieNerd
Mar 8, 2006, 03:49 PM
Is there an issue with where the mail is coming from? In the error email where it shows me a copy of it at the bottom, it shows the return address being

craigbowles@*my computer name*.local

Should this be configured to send mail via some account? Seems like that should make sense.

section.echo
Dec 29, 2010, 10:31 PM
I have a question.. I am trying to use crontab to send an email every day at 8pm.. with an attachment..when I use the mail command without crontab it works fine..but crontab never executes it.. dont know if its not finding the "mail" command or what.. I am fairly new at this, so any help will be greatly appreciated..

Here is what i'm using in the terminal:
crontab /Library/crontab.txt (This is where the crontab command is)

Then, in the .txt file it looks like this:

* 20 * * * mail -s "Log" emailaddress@whatever.com</Library/Widgets/Widget.txt

Now, using the simple mail command just like that without the " * 20 * * * " works perfectly, but trying to use crontab will not work, I know it's something simple but I just cant figure it out...

Thanks again!!

ulbador
Dec 29, 2010, 10:45 PM
* 20 * * * cat /Library/Widgets/Widget.txt | mail -s "Log" emailaddress@whatever.com


Try that.

chown33
Dec 29, 2010, 11:17 PM
This message thread was resurrected from March 2006. The OP has probably graduated by now.

ulbador
Dec 29, 2010, 11:21 PM
Ha, oops. Didn't even see that when i responded. Yeah, I'll just slink over here in the corner now....