Unix shell script required

April 25, 2011 at 10:32:13
Specs: Windows XP
Hi , hope someone can help..any help will be appreciated

I need a script that will run each day and check the previous days directory for 24 hourly files and email me to say all files found for previous day's data i.e.

/test/directory/save/20110424/
filename.201104240000
filename.201104240100
filename.201104240200
filename.201104240300
filename.201104240400
filename.201104240500
filename.201104240600
filename.201104240700
filename.201104240800
filename.201104240900
filename.201104241000
filename.201104241100
filename.201104241200
filename.201104241300
filename.201104241400
filename.201104241500
filename.201104241600
filename.201104241700
filename.201104241800
filename.201104241900
filename.201104242000
filename.201104242100
filename.201104242200
filename.201104242300

Thanks


See More: Unix shell script required

Report •

#1
April 25, 2011 at 10:52:08
what Unix shell are you using: sh, ksh, bash??

Report •

#2
April 25, 2011 at 11:34:46
sorry....sh

Report •

#3
April 25, 2011 at 14:13:02
First, getting yesterday's date in the bourne shell is very difficult. It's been described ad nauseum in computing.net so I used a perl script to get yesterday's date. If you don't like perl, let me know, and I'll send you the computing.net links so you can use a total shell solution.

Second, I'll leave the email part to you as I don't know if you have sendmail working or not:

#!/bin/sh

# Prints yesterdays date and time as it relates to (now - (24 hours)).
datestr=`perl -e '
my $xsecs = time();
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(($xsecs - 86400));
print $mon + 1, " $mday ", 1900 + $year, "\n";
'`

set -- `echo $datestr`
month=$1
day=$2
year=$3

if [ $month -lt 10 ]
then
   monthstr="0"$month
else
   monthstr=$month
fi

dirname="/test/directory/save/$year$monthstr$day"
basename="filename."
filestr="$basename$year$monthstr$day*"

cd $dirname
if [ $? -eq 0 ]
then
   rm -f mailfile.txt
   for file in $filestr
   do
      echo "$file" >> mailfile.txt
   done
fi


Report •

Related Solutions

#4
April 26, 2011 at 04:24:38
Thanks nails...working great but need help with email ..I do have sendmail working on server

Report •

#5
April 26, 2011 at 09:42:47
After creating the mailfile.txt, try the mailx command:

mailx -s "sending mailfile.txt" nails@nails.com < mailfile.txt


Report •

#6
April 26, 2011 at 10:42:17
Thanks Nails..works great

Report •

Ask Question