Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
05-07-2011, 08:24 AM
|
#1
|
Member
Registered: Feb 2011
Posts: 179
Rep:
|
How to send mail through script
Hi all,
I have written a shell script to take backup and by doubt is after tat i need a script tat it should send mail automatically to eg:user@domain.com tat 'the backup job has done successfull',after tat i need anyone help to write a shell program tat mail should send automatically after the backup job completed for the below program.
#!/bin/bash
mount -t cifs -o user="$1",password="$2" "$3"/"$1" "$4"
echo "Mounted Successfully">>/var/log/kannan
cd "$4""$5"
date=`/bin/date "+%Y.%m.%d.%H.%M.%S"`
mysqldump -u"$6" -p"$7" "$8" > $date.sql
echo "Backup taken">>/var/log/kannan
tar -zcvf $date.sql.tgz $date.sql
echo "mysqldump to tar">>/var/log/kannan
rm -rf $date.sql
echo "Removed old one">>/var/log/kannan
Thanks,
|
|
|
05-07-2011, 08:31 AM
|
#2
|
LQ Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
|
Hello,
You can mail from the command with:
Code:
mail -s "subject" user@domain.com
if your system is set up to forward that mail to a mailserver, i.e. if you have for example Postfix configured to relay messages to a mailserver/domain.
But as mentioned in your other thread you're forgetting an important issue. You'll receive a message, be it on console, or by mail, on ANY occasion, even if the command fails. You should incorporate a conditional message depending on the exit code of your commands for example. Have a look at this at TLDP: 3.2.5. Special parameters.
To learn more about Bash scripting I'd advice you to read the following:
Bash Guide for Beginners
Advanced Bash Scripting Guide
Please put code you post between CODE tags for readability.
Kind regards,
Eric
|
|
|
05-09-2011, 01:35 AM
|
#3
|
Member
Registered: Feb 2011
Posts: 179
Original Poster
Rep:
|
If i configure imap in my server i can able to send mail from command
Thanks,
|
|
|
05-09-2011, 01:37 AM
|
#4
|
LQ Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
|
Hello,
Does this mean you've got your problem solved? If so, then please mark this thread as solved. Have fun with Linux.
Kind regards,
Eric
|
|
|
05-09-2011, 02:24 AM
|
#5
|
Member
Registered: Aug 2007
Location: INDIA
Distribution: CentOS, RHEL, Fedora, Debian, Ubuntu, LinuxMint, Kali Linux, Raspbian
Posts: 166
Rep:
|
There is utility called sendEmail . you can download it from here. I am using it and it's good and easy tool. you can use it in your script without any extra efforts.
|
|
|
05-09-2011, 05:03 AM
|
#6
|
Member
Registered: Feb 2011
Posts: 179
Original Poster
Rep:
|
No my problem was not solved i have configured sendmail but not able to send mail,can u help me.
Thanks,
|
|
|
05-09-2011, 05:09 AM
|
#7
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by ramecare
No my problem was not solved i have configured sendmail but not able to send mail,can u help me.
Thanks,
|
What command have you tried? And what error message do you get (if any)? Please use CODE tags to embed the code and make it more readable.
|
|
|
05-09-2011, 05:38 AM
|
#8
|
Member
Registered: Feb 2011
Posts: 179
Original Poster
Rep:
|
Hi,
I used the below command.
mail -s "hi" ramkannan1988@gmail.com
When i try to send mail i got this error from error log:
May 9 16:04:09 itsupport sendmail[30433]: p49AY9qi030433: to=ramkannan_88@yahoo.com,ramkannan1988@gmail.com, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=60108, relay=[127.0.0.1] [127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
I was not able to identify wat would be the problem,can u give me some suggesion.
vi /etc/mail/sendmail.mc
DAEMON_OPTIONS(`Port=smtp,Addr=58.68.21.67, Name=MTA')dnl
:wq!
make -C /etc/mail
Thanks,
Last edited by ramecare; 05-09-2011 at 05:42 AM.
|
|
|
05-09-2011, 05:47 AM
|
#9
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
It looks like your sendmail daemon is not running, so it's not listening on port 25. Please, show us the output of the following commands to confirm my suspicion:
Code:
# ps -ef sendmail
# netstat -an | grep -w LISTEN
|
|
|
05-09-2011, 05:54 AM
|
#10
|
Member
Registered: Feb 2011
Posts: 179
Original Poster
Rep:
|
[root@itsupport ~]# netstat -an | grep -w LISTEN
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:2401 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:35175 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN
tcp 0 0 10.200.1.66:53 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:733 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN
tcp 0 0 :::80 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:953 :::* LISTEN
[root@itsupport ~]# ps -ef sendmail
ERROR: Unsupported option (BSD syntax)
********* simple selection ********* ********* selection by list *********
-A all processes -C by command name
-N negate selection -G by real group ID (supports names)
-a all w/ tty except session leaders -U by real user ID (supports names)
-d all except session leaders -g by session OR by effective group name
-e all processes -p by process ID
T all processes on this terminal -s processes in the sessions given
a all w/ tty, including other users -t by tty
g OBSOLETE -- DO NOT USE -u by effective user ID (supports names)
r only running processes U processes for specified users
x processes w/o controlling ttys t by tty
*********** output format ********** *********** long options ***********
-o,o user-defined -f full --Group --User --pid --cols --ppid
-j,j job control s signal --group --user --sid --rows --info
-O,O preloaded -o v virtual memory --cumulative --format --deselect
-l,l long u user-oriented --sort --tty --forest --version
-F extra full X registers --heading --no-heading --context
********* misc options *********
-V,V show version L list format codes f ASCII art forest
-m,m,-L,-T,H threads S children in sum -y change -l format
-M,Z security data c true command name -c scheduling class
-w,w wide output n numeric WCHAN,UID -H process hierarchy
Thanks,
|
|
|
05-09-2011, 06:04 AM
|
#11
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
There is no service listening on port 25 (the default smtp port). Be sure to have a line like this in your sendmail.mc:
Code:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
then try to restart the mail daemon.
|
|
|
05-09-2011, 06:11 AM
|
#12
|
Member
Registered: Feb 2011
Posts: 179
Original Poster
Rep:
|
Again i have to make this DAEMON_OPTIONS(`Port=smtp,Addr=58.68.21.67, Name=MTA')dnl to DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
Thanks,
|
|
|
05-09-2011, 06:29 AM
|
#13
|
Member
Registered: Feb 2011
Posts: 179
Original Poster
Rep:
|
Now ia have make this to DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
I send mail to
[root@itsupport ~]# mail ramkannan_88@yahoo.com
Subject: testmail by Ram kannan
ramkannan
.
Cc: harish@ecaretechlabs.com
[root@itsupport ~]#
i did not recieve any mail & in the mail log i got the error
May 9 16:53:49 itsupport sendmail[32518]: p49BNnnK032518: from=root, size=84, class=0, nrcpts=2, msgid=<201105091123.p49BNnnK032518@itsupport.ecaretechlabs.com>, relay=root@localhost
May 9 16:53:49 itsupport sendmail[32519]: p49BNnx5032519: from=<root@itsupport.ecaretechlabs.com>, size=375, class=0, nrcpts=2, msgid=<201105091123.p49BNnnK032518@itsupport.ecaretechlabs.com>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
May 9 16:53:49 itsupport sendmail[32518]: p49BNnnK032518: to=ramkannan_88@yahoo.com,harish@ecaretechlabs.com, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=60084, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (p49BNnx5032519 Message accepted for delivery)
May 9 16:53:52 itsupport sendmail[32521]: STARTTLS=client, relay=ecaretechlabs.com., version=TLSv1/SSLv3, verify=FAIL, cipher=AES256-SHA, bits=256/256
May 9 16:53:53 itsupport sendmail[32521]: p49BNnx5032519: to=<harish@ecaretechlabs.com>, ctladdr=<root@itsupport.ecaretechlabs.com> (0/0), delay=00:00:04, xdelay=00:00:04, mailer=esmtp, pri=150375, relay=ecaretechlabs.com. [204.93.168.132], dsn=5.1.1, stat=User unknown
I was not able to find the solution,can anyone helpme on this
Thanks,
Last edited by ramecare; 05-09-2011 at 06:43 AM.
|
|
|
05-10-2011, 11:44 AM
|
#14
|
Member
Registered: Oct 2006
Location: Slovak Republic
Distribution: Slackware 14.2, current
Posts: 461
Rep:
|
Lets take this from the begining. It seems to me that you want to make too many steps at once.
1. Your first step should be the sendmail configuration.
2. After this you can think about to write a script which sends mail
Maybe I missed this but it is useful to know these basic things:
1. What distribution of Linux you use.
2. What are the steps which you do when you configure your sendmail.
(1. You should edit your sendmail.mc file, 2. use m4 to generate your sendmail.cf file from the sendmail.mc, 3. copy it to the corect directory ...)
3. What command you use to start your sendmail.
Because it is obvious that you did't configured your sendmail correctly yet, you should focus on this step first. Please answer the questions above.
Last edited by hua; 05-10-2011 at 11:46 AM.
|
|
|
All times are GMT -5. The time now is 04:14 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|