Operating System - HP-UX
1828656 Members
8334 Online
109983 Solutions
New Discussion

Script to send mail every monday.

 
SOLVED
Go to solution
bhaskaran
Occasional Advisor

Script to send mail every monday.

Iam maintaining a file , which i update every sunday morning. i want this to be mailed on monday morning, either when i invoke unix or before noon.

can anybody help me.
6 REPLIES 6
Alex Lavrov
Regular Advisor

Re: Script to send mail every monday.

You can make a script that mails your file,
and schedule it in crontab to run every monday.
Mark Grant
Honored Contributor

Re: Script to send mail every monday.

why don't you put the script in cron

An entry like

0 11 * * 1 myscript

will send the mail out an 11.00 every monday.
Never preceed any demonstration with anything more predictive than "watch this"
bhaskaran
Occasional Advisor

Re: Script to send mail every monday.

It's ok to include in cron, but our administrator has disabled cron, is their any other option.
please do help me...
Mark Grant
Honored Contributor

Re: Script to send mail every monday.

You only other option is to write a script yourself that never exits but sleeps for 24 hours and then checks the day before sending a mail. "date +%u" will return a day number and 1 is Monday.
Never preceed any demonstration with anything more predictive than "watch this"
Kent Ostby
Honored Contributor

Re: Script to send mail every monday.

I have something like this.

It reads the date using the date command and then it checks the keys in a data file.

If any of the keys match either the day of the week or the month/day combination then part of the matching line is put into the subject field and the whole file is emailed.

I use this as a way of doing todo lists for myself. I run it out of cron each day.

Here is my script. After that I will list the awk script that is called. I'm sure it could be cleaned up, but it certainly works.

~/notes is the directory where I keep my todo lists.

#!/bin/sh
cd ~/notes
touch .ml0000
rm .ml*
date | awk '{print $1,$2$3}' | tr "[:lower:]" "[:upper:]" > .ml0000
cat .ml0000 > .ml0010
cat standard_notes >> .ml0010
awk -f ~/bin/ml.awk < .ml0010 > .ml0020
if [ -s .ml0020 ]
then
mailx -s " `cat .ml0020`" youremailaddresshere@yahoo.com < standard_notes
fi

Here's the awk script

BEGIN {printit="";}
NR==1 {keyone=$1; keytwo=$2;next}
keyone==$1 {printit=printit" / "substr($0,8,13);}
$1=="EVERY" {printit=printit" / "substr($0,8,13);}
$1=="WKED" {if(substr(keyone,1,1)=="S") printit=printit" / "substr($0,8,13);}
$1=="WKDY" {if(substr(keyone,1,1)!="S") printit=printit" / "substr($0,8,13);}
keytwo==$1 {printit=printit" / "substr($0,8,13);}
END {
if ( length(printit) > 2 )
print printit}

Sample line is:
THU Close calls

The script is looking at the first field to see if matches the right day of the week or date.

I will post a subset of this that just does mondays below.

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Kent Ostby
Honored Contributor
Solution

Re: Script to send mail every monday.

#!/bin/sh
touch .mailit.uu1
rm .mailit.uu*
date | awk '/^Mon/' > .mailit.uu1
if [ -s .mailit.uu1 ]
then
mailx -s "Your message" kmo < messagefile
fi
exit

You would have to start up this script either via cron as mentioned earlier (and cron can do the mailing for you) ... or in a startup file on your system.
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"