Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NewbieNerd

macrumors 6502a
Original poster
Sep 22, 2005
512
0
Chicago, IL
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

macrumors 6502a
Original poster
Sep 22, 2005
512
0
Chicago, IL
I forgot to mention, yes I do enter

crontab *filename*

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

plinden

macrumors 601
Apr 8, 2004
4,029
142
NewbieNerd said:
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

Administrator
Staff member
Sep 19, 2002
39,782
7,514
Los Angeles
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

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
I too had the same issue when trying to pipe the echo into the mail command. Then I tried to use

Code:
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
 

NewbieNerd

macrumors 6502a
Original poster
Sep 22, 2005
512
0
Chicago, IL
kingjr3 said:
found a command that can "notify" you that cron worked. Courtesy of ADC

* * * * * 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

Code:
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

macrumors 6502a
Original poster
Sep 22, 2005
512
0
Chicago, IL
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

macrumors newbie
Dec 29, 2010
2
0
Need help with crontab and mail command

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

macrumors 68000
Feb 11, 2010
1,554
0
Ha, oops. Didn't even see that when i responded. Yeah, I'll just slink over here in the corner now....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.