Re: Configuring FreeBSD 6.2 to use sendmail for sending only



At 08:14 PM 8/30/2007, L Goodwin wrote:

--- Derek Ragona <derek@xxxxxxxxxxxxxxxxxxxxxxxx>
wrote:

> At 07:01 PM 8/30/2007, L Goodwin wrote:
> >Chuck, I'd prefer to have the script handle the
> >mailing so I can test the script (with email send)
> >manually, independent of cron.
> >
> >Still looking for specifics on setting this up and
> a
> >bourne shell script example that sends an email.
> >Thanks!
> >
> >--- Chuck Swiger <cswiger@xxxxxxx> wrote:
> >
> > > On Aug 30, 2007, at 3:12 PM, L Goodwin wrote:
> > > > I wrote a shell script that backs up the file
> > > server.
> > > > I would like to modify this script to email a
> > > > notification message to a public email
> address.
> > >
> > > Use cron, which will automatically email out the
> > > results of your
> > > script to any email address you like.
> > >
> > > > Seems like sendmail should do the job nicely,
> but
> > > I've never set it
> > > > up before.
> > > >
> > > > What specific steps (including
> network-specific)
> > > need
> > > > to be performed to get sendmail working for
> > > outgoing
> > > > mail only in a secure manner?
> > >
> > > Please see the fine Handbook:
> > >
> > >
> > >
>
>http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/mail.html
> > >
> > > Although, it is entirely reasonable to consider
> > > using Postfix instead.
> > >
> > > --
> > > -Chuck
> > >
> > >
>
> Here is a sample script that you can use as a
> template:
=======================================================
> #!/bin/sh
>
> #define any commands you will use
> MAILFILE=mymailfile
> MAILFILE2=mymailfile2
> SENDTO=derek@xxxxxxxxxxxxxxxxxxxxxxxx
> CCTO=derek@xxxxxxxxxxxxxxxxxxxxxxxx
> MAIL=/usr/bin/mail
> AWK=/usr/bin/awk
> CAT=/bin/cat
> TR=/usr/bin/tr
> TEMPDIR=/tmp
>
> #make sure we have paths
> export PATH=$PATH:/usr/local/sbin:/usr/local/bin
>
> cd $TEMPDIR
> $CAT /etc/passwd | $AWK -F : '{ print $5 }' >
> $MAILFILE
> $TR -cd "\012-\172" < $MAILFILE > $MAILFILE2
> $MAIL -s "My list of real user names subject"
> $SENDTO -c $CCTO < $MAILFILE2
=======================================================

Derek, your example brings up another question.

Should I be calling "mail" or "sendmail", and which
mail or sendmail should I invoke if there is more than
one of either? Chuck's example calls sendmail in a
path that does not exist on my system (my sendmail is
in /usr/sbin/). I usually invoke whichever one is
first in my path.

Mail is the local MTA to send via sendmail. All my servers run sendmail.


One more question. Is it ok to run the script (and
send the email) as user root, or should I create a
user account with more limited permissions -- if so,
what limits should I set?

Some scripts may need to run as root. I have cron jobs I run as root, as root permissions are required. Other jobs I run as non-root users. Typically to run non-root jobs, create a new user group or use one that is existing and make a new user that is a member of that group. Typically a non-root task is analysis of webserver logs, since the webserver should run with non-root privileges.

You can also use complex scripts where you combine root and non-root tasks using sudo for the root tasks.

Like most tasks in a UNIX environment, there are many ways to do them.

-Derek

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.

_______________________________________________
freebsd-questions@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • IBM Informix Web DataBlade: Local root by design
    ... IBM Informix Web DataBlade: Local root by design ... Impact: Any user who can: 1) Save a Perl script anywhere on the server's ... admin right on any database can do it by loading the WDB module into ...
    (Bugtraq)
  • Re: Output to file lost when using cron
    ... > When executing as 'root' user it sends the output to the file ... If I have the script run from cron no output is generated. ... Did you change the crontab ...
    (comp.unix.aix)
  • RE: Linux hacked
    ... I would also suggest using a simple script in the future that alerts ... Subject: Linux hacked ... To get back into your account you want to use, at the boot manager ... boot normally and you should be able to login as root with your new ...
    (Security-Basics)
  • Re: BSDstats v3.0 - The Security Rewrite
    ... The bsdstats script could easily pick up that entry and set ... a management machine, and that management machine only has ... Email is sent to root containing IDTOKEN= as generated by host, root forwards that to rpt@xxxxxxxxxxxx, rpt@xxxxxxxxxxxx sends back KEY= value ... second time, submits report values to root, root forwards that to rpt@xxxxxxxxxxxx ... ...
    (freebsd-questions)
  • Re: Great SWT Program
    ... from a terminal emulator and log in as root there. ... terminal-emulator windows open, ... The script, suid-root utility, or whatever would ... the command interpreter with root privileges ...
    (comp.lang.java.programmer)