Sponsored Content
Top Forums Shell Programming and Scripting Script Contain Send Mail via Telnet Post 302880341 by kris.adrianto on Thursday 19th of December 2013 02:29:25 AM
Old 12-19-2013
Script Contain Send Mail via Telnet

Dear Masters,

I am using Solaris 10 and bash shell. I make a script for checking if a file is exists on the specified folder or not from 5th day of the month until the end of the month. If the file doesn't exist, the script will send email to me. The script ran perfectly when I execute it on foreground. But when I put it on crontab, it doesn't send me email when the script is finished.

Below is the script for checking file:
Code:
#!/bin/sh
day=`date +%d`
month=`date +%m`
lmonth=`expr $month - 1`
if test "$lmonth" = "0"
        then
        lmonth=12
        year=`expr $year - 1`
fi
year=`date +%Y`
hour=`date +%H`
sales=_SALES.csv
filename=$year$lmonth$sales
text="This file is not found on the server:"
sales_dir=/sales/
did=`cat /test-script/var`

if day=05 && hour=8
        then
                did=0
                echo "$did" > /test-script/var
fi

if did=0
        then
                cd $sales_dir
                if [ -f $filename ]
                        then
                        did=1
                        echo "$did" > /test-script/var
                        echo "File found - $date" >> /test-script/sales.log
                else
                        echo "$text" > /test-script/mail/mail.txt
                        echo "$filename" >> /test-script/mail/mail.txt
                        /test-script/sendmail.sh |telnet > /test-script/mail/mail.log
                fi
        else
                exit 0
        fi

The script will send mail via telnet. Below is the script for sending mail:

Code:
#!/bin/sh
host=10.14.1.105
port=25
echo open $host $port
sleep 1
echo helo $host
sleep 1
echo mail from:salesreport@company.com
sleep 1
echo rcpt to:kris.@company.com
sleep 1
echo data
sleep 1
echo to:kris.@company.com
sleep 1
echo subject:SALES REPORT File Not Found!
sleep 1
echo ""
sleep 1
echo ""
sleep 1
cat /test-script/mail/mail.txt
sleep 1
echo .
sleep 1
echo quit
#end

Need your help to guide me on this case.
Thanks in advance.
Kris

Last edited by kris.adrianto; 12-19-2013 at 03:31 AM.. Reason: post not appear
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Send e-mail in Shell script

How to send an error mail from a shell script e.g. mail destination_adr@blabla.int "Message : here an error message " thanks, Ann. (1 Reply)
Discussion started by: annelisa
1 Replies

2. Shell Programming and Scripting

shell script to send a mail

Hi, I need a shell script which runs in the backround for all the 24 hours and send a mail to us regarding the output of the prstat command when the load average increase above certain percent. kindly help me on this...... (1 Reply)
Discussion started by: jayaramanit
1 Replies

3. Shell Programming and Scripting

Shell script to send a mail

Hi , I need to prepare a script which will check my database with specific to particluar table. If the row count exceeds a certain limit, i need to send a mail to a set of Recipients. Being new to unix, please guide me to complete this task. Advance thanks, Sekar. (4 Replies)
Discussion started by: Sekar1
4 Replies

4. UNIX for Advanced & Expert Users

need to configure mail setting to send mail to outlook mail server

i have sun machines having solaris 9 & 10 OS . Now i need to send mail from the machines to my outlook account . I have the ip adress of OUTLOOK mail server. Now what are the setting i need to do in solaris machines so that i can use mailx or sendmail. actually i am trying to automate the high... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

5. Shell Programming and Scripting

Help-send mail script

Hi, I have written one script for sending mails with attachment. currently its working for only one recipient. I want to send mails to n number of users by taking user input i.e number of users. Output of current script: Enter how many files : 1 Enter First Name : kiran E-Mail... (2 Replies)
Discussion started by: kiran_j
2 Replies

6. Shell Programming and Scripting

script to send mail !!

Hi Experts.. i have created a table with the fields, empid name mailid 1 raja raja@xy.com and entered the values of all persons who are in that file... i have a .csv file date shift1 shift2 6/6/2011 ram raja Now i want a script that could fetch the data in (input file .csv file) and... (3 Replies)
Discussion started by: cratercrabs
3 Replies

7. Shell Programming and Scripting

To send a mail through shell script

I want to send a mail through shell script,If it is possible Please give me a code. mail id : upload.xxx@example.com (8 Replies)
Discussion started by: kannansoft1985
8 Replies

8. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

9. UNIX for Advanced & Expert Users

Client was not authenticated to send anonymous mail during MAIL FROM (in reply to MAIL FROM comm

I am having trouble getting mail to work on a red hat server. At first I was getting this message. Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to :25: Connection refused Then added the port to my firewall. Then I temporarily turned off selinux. I then copied this file... (1 Reply)
Discussion started by: cokedude
1 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 02:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy