mail and cron in the terminal

Discussion in 'Mac Programming' started by NewbieNerd, Mar 8, 2006.

  1. macrumors 6502a

    NewbieNerd

    Joined:
    Sep 22, 2005
    Location:
    Chicago, IL
    #1
    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.
     
  2. thread starter macrumors 6502a

    NewbieNerd

    Joined:
    Sep 22, 2005
    Location:
    Chicago, IL
    #2
    I forgot to mention, yes I do enter

    crontab *filename*

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

    plinden

    Joined:
    Apr 8, 2004
    #3
    What do you see using "crontab -l"?
     
  4. Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #4
    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.
     
  5. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #5
    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
     
  6. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #6
    found a command that can "notify" you that cron worked. Courtesy of ADC

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

    where loginname is your short name.
     
  7. thread starter macrumors 6502a

    NewbieNerd

    Joined:
    Sep 22, 2005
    Location:
    Chicago, IL
    #7
    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
     
  8. thread starter macrumors 6502a

    NewbieNerd

    Joined:
    Sep 22, 2005
    Location:
    Chicago, IL
    #8
    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.
     
  9. macrumors newbie

    Joined:
    Dec 29, 2010
    #9
    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!!
     
  10. ulbador, Dec 29, 2010
    Last edited: Dec 29, 2010

    macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #10
    Try that.
     
  11. macrumors 603

    Joined:
    Aug 9, 2009
    #11
    This message thread was resurrected from March 2006. The OP has probably graduated by now.
     
  12. macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #12
    Ha, oops. Didn't even see that when i responded. Yeah, I'll just slink over here in the corner now....
     

Share This Page