Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am running OS X 10.7 and I am learning unix commands. I would like to set up a very basic cron job that sends me an email with a certain message.

How would I go about this. From what I have read, I should receive an email automatically unless I specify otherwise.

I don't seem to have the crontab file in the /etc directory.

Any help is more than appreciated.

share|improve this question
2  
I don't know MacOS, but usually crontab files are not stored in /etc. But anyway, you not need to know where they are. Use the crontab -e command for editing, it will know the location. –  manatwork Feb 14 '12 at 13:24
    
I think I have found that already then, I tried changing to the root directory then to /etc then list all files however its not there. As you say, its not an issue though. I have created a job I think that prints a line of text, but I don't know where the output is saved, also, how can I get it to email me said message? –  Mike Feb 14 '12 at 13:32
add comment

3 Answers

cron automatically emails you the output ( if any ) of the jobs it runs. Of course, you have to have an email server ( eg. postfix ) installed for this to work.

share|improve this answer
    
Would OS X Lion Server work? –  Mike Feb 14 '12 at 14:48
    
@Mike, I believe that is an OS product, not an SMTP server. –  psusi Feb 14 '12 at 15:01
    
If I had my own hosted server, would this work if I saved the settings somewhere? –  Mike Feb 14 '12 at 15:03
    
@Mike, I have no idea what you are asking. You need to be running an SMTP server that accepts mail on port 25 and delivers it to the correct mailbox. –  psusi Feb 14 '12 at 15:10
    
I have a website with SMTP email, If I used those server settings could I send email from cron jobs? –  Mike Feb 14 '12 at 15:21
show 1 more comment

You can send yourself an email using this solution: http://mabblog.com/blog/2011/09/lion-smtp-postfix-relay-and-dreamhost/comment-page-1/#comment-264118

Note that the only parts that are NOT literal are references to "you@domain.com" and "username@domain.com:password". Provide appropriate values for them.

Leave the brackets in, don't change the port address (587) and leave "mail.domain.com" as is.

share|improve this answer
add comment

You have to set up a whole mail infrastructure for this to work. Personally, I use esmtp (a program that emulates sendmail) and procmail (a mail delivery agent), in this way I can get messages from cron jobs. However, if I were you I'd think twice whether it's worth the hassle, because mail servers can be, and usually are, a real headache to set up.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.