Mail function in shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mail function in shell scripting
# 1  
Old 05-23-2013
Mail function in shell scripting

Hi Guys,

i'm new to scripting, please help me to write the script.

Purpose: To write a simple addition program and to mail the output result.

Script:
Code:
#!/bin/bash
echo "entr numbers";
read n1;
read n2;
answer=$(($n1+$n2));
echo $answer > mail -s "output"  karthic324n@gmail.com;


i'm not getting the result mail. Any idea to solve the problem??

Last edited by Franklin52; 05-24-2013 at 03:16 AM.. Reason: Please use code tags
# 2  
Old 05-23-2013
Pls use code tags as required by forum rules!

Try to pipe echo's output to mail instead of (faultily!) redirecting it!
# 3  
Old 05-24-2013
Thanks Rudic for your reply!

Hi rudic, thank you very much for your reply. I even tired to pipe the output. But of no use. I use ubuntu, should i do any network changes? to get the output mail?
# 4  
Old 05-24-2013
Hi Karthick.

Just as a check to see if your mail command is working correctly, you could view the mail log.

For me it is in /var/log and called 'mail' although yours may be different (maybe maillog)

You should be able to see in there whether the mail is even being queued.

There should also be an error log for mail (ours is called mail.warn and there's a mail.error too) which may give you some pointers as to why the mail is not being sent.

If you cannot find your mail logs but are on your workplace network, you could also try sending a mail to your internal email address first and see if that arrives successfully, if so then this would indicate some changes are needed to mail externally.
# 5  
Old 05-25-2013
Thanks JPT

Hi Jpt,


Thank you, Very much for your reply. It got solvedSmilie. i checked in the mail log and found out the problem.

Thanks againSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

New to Shell Scripting: Need help interpreting example function

In this example function below, I cannot figure out what certain parts mean. if ! echo $PATHwhat is "if !"? (^|:)$1($|:) What is ^|: and$|:? pathmunge () { if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then if ; then PATH=$PATH:$1 else... (3 Replies)
Discussion started by: MemberName
3 Replies

2. Shell Programming and Scripting

Need help to write a function in shell scripting to execute sql files

Hi, I am new to shell scripting and i need to write a automation script to execute sql files. I need to check the table if it is there in system tables and need to write a function to call the .sql files. For ex. I have a.sql,b.sql,c.sql files, where the sql file contains DELETE and INSERT... (1 Reply)
Discussion started by: Samah
1 Replies

3. Homework & Coursework Questions

Creating a function that sends a mail using mail command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The function will be called m and it will allow you to send an email to someone using the mail command. The... (1 Reply)
Discussion started by: Drucian
1 Replies

4. Shell Programming and Scripting

How to send mail using PHP mail function On apache server.?

Hello, I am using centos-6.2 I have apache server,php5 on my system and I want to send mail using sendmail on my system. when I try to send mail from shell that time mail is succesfully sent to respective address() but when I try to send it through webbrowser I am not able to send it.... (1 Reply)
Discussion started by: Kiran ursal
1 Replies

5. Shell Programming and Scripting

Shell Scripting Function call return value

Hi I have a function : Make_Report() { trx_report=`sqlplus -s $conn_str << @@ set echo off; set pages 0; set feedback off; set verify off; select srv_trx_s_no,... (1 Reply)
Discussion started by: neeraj617
1 Replies

6. Shell Programming and Scripting

/usr/bin/time Shell Scripting Function

Hello, I have made a Linux Shell Script that downloads 6 files from the Internet and then deletes them. Now i want to use the function "/usr/bin/time" and "bc" to calculate how long the avergate run time for the shell script is. I therefore need to do it 100 times. My shell script code is below: ... (6 Replies)
Discussion started by: solo2
6 Replies

7. Shell Programming and Scripting

Reading a file and sending mail by shell scripting?

hi I need help urgently...i need to write a shell script which can solve the following problem....its urgent plz help me out coz m totally newbie in shell scripting.... the problem is: Suppose I have a folder called logs. whenever some error occurs some correspondence error file is generated. I... (4 Replies)
Discussion started by: sukhdip
4 Replies

8. Shell Programming and Scripting

Insert a function in a jsp file using Shell scripting

Greetings to all.I am new to the forum as well as to UNIX as well.I have a jsp file which has the following selectedStartMonth = request.getParameter( "startMonth" ); selectedStartDay = request.getParameter( "startDay" ); selectedStartYear = request.getParameter( "startYear" );... (3 Replies)
Discussion started by: 20033716
3 Replies

9. Shell Programming and Scripting

Sed function is shell scripting

Hello everybody, I trying to convert a text inside my file that looks something like this: into hyperlink so that the user can click onto it..... I tried this but doesn't work cat mylist9.html |sed -e '<a href="' >mylist13.html Thanks (13 Replies)
Discussion started by: kev_1234
13 Replies

10. Shell Programming and Scripting

Function loading in a shell scripting like class loading in java

Like class loader in java, can we make a function loader in shell script, for this can someone throw some light on how internally bash runs a shell script , what happenes in runtime ... thanks in advance.. (1 Reply)
Discussion started by: mpsc_sela
1 Replies
Login or Register to Ask a Question