Compare the dates and send mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare the dates and send mail
# 1  
Old 02-19-2015
Compare the dates and send mail

Hi Guys,

I am new to this fourm. Need your help to complete my requirment.

Below is my requirment.

Have to check expiry of the certificate. Compare the certificate expiry date with current date. If the difference is less than 30 days, need to send mail.

Code:
#!/usr/bin/ksh
file="sslexpiry" #the file where you keep your string expiry date

name=$(cat "$file")        #the output of 'cat $file' is assigned to the $name variable
 
date > todate.ext #the file where you keep current date value

file1="todate.ext"  #the file where you keep your string current date

todaydate=$(cat "$file1") #the output of 'cat $file1' is assigned to the $todaydate variable
 
 
echo $name
echo $todaydate

---
I can print the dates as below

Code:
Fri Apr 10 18:59:59 CDT 2015
Thu Feb 19 18:50:52 CST 2015

--
Now i have to count the number of days between these two dates. After that need to sent mail if this value is less than 30.

Could you please help me to complete the script.

Thanks,
Ramesh

Last edited by Don Cragun; 02-21-2015 at 03:38 AM.. Reason: Add CODE tags.
# 2  
Old 02-20-2015
How is the file sslexpiry created?
# 3  
Old 02-21-2015
You probably have to cheat and use something like perl or php. The following might do:

Code:
days=`perl -e 'use Date::Parse; print int((str2time($ARGV[1])-str2time($ARGV[0]))/86400);' "$name" "$todaydate"`
if [ "$days" -lt 30 ]; then
   echo "send mail..."
fi

If you have a fancy version of the date command like on linux you can also do the following:

Code:
days=$(( (`date --date="$name" +%s` - `date --date="$todaydate"  +%s`)/86400 ))
if [ "$days" -lt 30 ]; then
   echo "send mail..."
fi


Last edited by Walter Misar; 02-21-2015 at 05:21 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Beginners Questions & Answers

Shell script to compare text and send a mail

Hello, Somebody can help me to develop a script for the below requirement I have a 3 files in a directory which was dynamically changed everyday basis. I need a script to fetch the 1pattern of strings in each file. if the three matching pattern is same send a mail with subject as success else... (1 Reply)
Discussion started by: MATHANKUMAR
1 Replies

3. Ubuntu

Not able to send mail out of UbuntuBox in send mail

Hi Guys.. yesterday i purchased a VPS server and installed sendmail on ubuntu 12.4 with Webmin & Apache runing webserver problem is.. i can send mail via webmin user interface account to anybody to out side to any domain and able to recieve any mail from any domain.. Now main... (2 Replies)
Discussion started by: cmdman
2 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. UNIX for Advanced & Expert Users

How can I send a mail from my outlook or other mail accounts to UNIX server?

Hi all, I want to send a mail for my business needs from outlook account to an unix server (HP-UX) but I don't send any mail. While I can send from the unix server to my outlook account, I can't send from outlook to unix. How can I achieve this ? How can I send a mail from my outlook or other... (2 Replies)
Discussion started by: igelegin
2 Replies

6. 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

7. UNIX for Dummies Questions & Answers

How to send html file in a mail not as an attachment but it should display in the mail in table for

Hi The below script working when we are sending the html as attachment can u please guide how to send thesmae data in table form direct in the mail and not in mail attachment . cat Employee.sql SET VERIFY OFF SET PAGESIZE 200 SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD... (0 Replies)
Discussion started by: mani_isha
0 Replies

8. Shell Programming and Scripting

Compare dates

Need to find all records where date in one filed is greater than date in other. Input: ABC 2 Filed3 CDG * X 20080903 20081031 180.00 ABD 2 Filed3 CDG * X 20081101 20081031 190.00 ABE 2 Filed3 CDG * X 20090903 20081031 120.00 ABC 2 Filed3 CDG * X 20080903 20081015 130.00 Output: ... (2 Replies)
Discussion started by: necroman08
2 Replies

9. UNIX for Advanced & Expert Users

send attachments using send mail in Solaris

Hi All, I have a requirement to send and email of body html with an attachment. concatinating uuencode output to the mail body with mailx command works, but as my Email body is of HTML type i use sendmail. my command to send HTML body is as below: export MAILTO="recipient@domain.com"... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

10. UNIX for Dummies Questions & Answers

can not send mail from unix server to company/yahoo mail

hi, Gurus, I need some help with sending mail out from my UNIX server: It is running Solaris 2.6 and the sendmail version is 8.8. Output of :/usr/lib/sendmail -d0.1 -bt < /dev/null Version 8.8.8+Sun Compiled with: LOG MATCHGECOS MIME7TO8 MIME8TO7 NAMED_BIND NDBM NETINET ... (5 Replies)
Discussion started by: b5fnpct
5 Replies
Login or Register to Ask a Question