Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a bash script that is sending an email through command line mutt. This bash script is being called from a cron job (setup using crontab -e because of permissions needed to do all items in the script). I set the from address so that users can reply (which works fine), but the name being shown is "root". This is causing some confusion. Is there an actual way to set the name associated with the email address?

The email portion of the script is below:

EMAIL=me@domain.com
export EMAIL

mutt -s "subject" -a /home/user/directory/file*.xls -- user1@domain.com, user2@domain.com < /home/user/directory/message.txt

Thanks

Kevin

share|improve this question
    
I'm curious, does the email just say "From: Root <root@domain>" or does it say "From: Root <me@domain.com>"? –  ruffEdgz May 17 '12 at 19:58
    
@ruffEdgz it says "root <me@domain.com>" –  klcant May 18 '12 at 2:18
    
@klcabt then my solution should work or just update your EMAIL variable to look like my example below (with the name and email address). –  ruffEdgz May 18 '12 at 13:48
    
@ruffEdgz That is what I was looking for. Thanks for your help! –  klcant May 18 '12 at 18:30
add comment

2 Answers

up vote 2 down vote accepted

The easiest way to make sure the email that is sending with the correct name would be to run the cron job on the account you need it to send out:

Example

me@domain:~$ crontab -e

If you want the root user to send out the messages through mutt, try this one liner (it worked for me):

export EMAIL="Me <me@domain.com>" && mutt -s "subject" -a /home/user/directory/file*.xls -- user1@domain.com, user2@domain.com < /home/user/directory/message.txt

Hope this helps.

share|improve this answer
    
Putting the name and address in quotes was the secret sauce! Thanks! –  klcant May 18 '12 at 18:31
add comment

Use /etc/crontab instead of cron since you can use that to include a username that is used to start the command you need to start.

Example:

more /etc/crontab 

shows

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repor
t /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repor
t /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repor
t /etc/cron.monthly )
#

Include your line from cron into this file and add the username between dow (day of week) and command. The script will then be started as that user.

This is a bit better than doing this in a users crontab since you can include the same line in here for every user you need it and do not need to maintain several crontabs.

If you need root to access certain files you should change the permissions for it or create a group that includes that command and your users.

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.