Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How or can you perfrom the following

Status
Not open for further replies.

tot

IS-IT--Management
Feb 1, 2002
1
KE
I and far from being a knowledgible scripter but i am trying. I am trying to write a script that will take the following data
01/22/02 00:42:10 tapemgr backup 0
01/23/02 00:23:53 tapemgr backup 0
01/24/02 00:01:00 tapemgr backup 0
01/25/02 00:26:23 tapemgr backup 0
01/26/02 00:07:00 tapemgr backup 0
01/27/02 00:02:56 tapemgr backup 0
01/27/02 22:05:12 tapemgr backup 3
and convert the 01/22/02 dates to sun - sat and cout back atleast 3 weeks so with the information i can have it to display 3 sunday with either 3 (3) or (0) but the correct backup completion

can anyone help or point me in the right direction
thanks
 
Hi Tot,

Here's a little script that I just threw together for you...

There may be an easier way... There may be a better way...

But it's the first thing that came to my mind, and I tested it... It works...

-------------------
#!/usr/bin/ksh

FILE=$1

tail -30 $FILE | awk '{print $1, $2, $3, $4, $5}' | while read DATE TIME MGR TYP
E INC
do
MO=`echo $DATE | awk -F/ '{print $1}'`
DAY=`echo $DATE | awk -F/ '{print $2}'`
YR=`echo $DATE | awk -F/ '{print $3}'`
YEAR=20$YR
COUNT=1
cal ${MO} ${YEAR} | grep -v "$YEAR" | grep -v "S" | awk '{print $1, $2, $3, $
4, $5, $6, $7}' | while read SUN MON TUE WED THU FRI SAT
do

if [ "$COUNT" = "1" ]
then
if [ ! -n "$MON" ]
then
SAT=$SUN
FRI=""
THU=""
WED=""
TUE=""
MON=""
SUN=""
elif [ ! -n "$TUE" ]
then
SAT=$MON
FRI=$SUN
THU=""
WED=""
TUE=""
MON=""
SUN=""
elif [ ! -n "$WED" ]
then
SAT=$TUE
FRI=$MON
THU=$SUN
WED=""
TUE=""
MON=""
SUN=""
elif [ ! -n "$THU" ]
then
SAT=$WED
FRI=$TUE
THU=$MON
WED=$SUN
TUE=""
MON=""
SUN=""
elif [ ! -n "$FRI" ]
then
SAT=$THU
FRI=$WED
THU=$TUE
WED=$MON
TUE=$SUN
MON=""
SUN=""
elif [ ! -n "$SAT" ]
then
SAT=$FRI
FRI=$THU
THU=$WED
WED=$TUE
TUE=$MON
MON=$SUN
SUN=""
fi
COUNT=2
fi

if [[ "$DAY" = "$SUN" || "$DAY" = "0$SUN" ]]
then
echo "Sun $DATE $TIME $MGR $TYPE $INC"
elif [[ "$DAY" = "$MON" || "$DAY" = "0$MON" ]]
then
echo "Mon $DATE $TIME $MGR $TYPE $INC"
elif [[ "$DAY" = "$TUE" || "$DAY" = "0$TUE" ]]
then
echo "Tue $DATE $TIME $MGR $TYPE $INC"
elif [[ "$DAY" = "$WED" || "$DAY" = "0$WED" ]]
then
echo "Wed $DATE $TIME $MGR $TYPE $INC"
elif [[ "$DAY" = "$THU" || "$DAY" = "0$THU" ]]
then
echo "Thu $DATE $TIME $MGR $TYPE $INC"
elif [[ "$DAY" = "$FRI" || "$DAY" = "0$FRI" ]]
then
echo "Fri $DATE $TIME $MGR $TYPE $INC"
elif [[ "$DAY" = "$SAT" || "$DAY" = "0$SAT" ]]
then
echo "Sat $DATE $TIME $MGR $TYPE $INC"
fi

done
done
----------------

You would execute this script with the following syntax:

<script> <data_file>

Example:

> check_logs log.out

Hope this helps...

Joe F.
 
Hi,

This ksh script display the lines of your file for the days last days.
All displayed lines are prefixed by the day of week (Sun-Sat).

LastDays.shl your_file 21

will display lines from 01/13/01 to 01/27/01 (last date of the file).


LastDays.ksh


File=${1:?&quot;Usage: $0 file [days]&quot;}
Days=${2:-28}
LastDate=$(tail -1 $File | awk '{print $1}')
awk -v LAST=&quot;$LastDate&quot; -v DAYS=&quot;$Days&quot; -f LastDays.awk $File


LastDays.awk

Note: The CalDate function isn't use here
but may be usefull


#===================================================
# F U N C T I O N S
#====================================================

#----------------------------------------------------
# Convert Julian to calendar date
#----------------------------------------------------

function CalDate(jj, a,b,c,d,e,f,x,w,z,dd,mm,yy) {
#sub(&quot;,&quot;,&quot;.&quot;,jj)
z = jj + 0.5
w = int((z - 1867216.25) / 36524.25)
x = int(w / 4.0)
a = z + 1.0 + w - x
b = a + 1524.0
c = int((b - 122.1) / 365.25)
d = int(365.25 * c)
e = int((b - d) / 30.6001)
f = int(30.6001 * e)
dd = b - d - f
if (e < 13.5)
mm = e - 1
else
mm = e - 13
if (mm > 2.5)
yy = c - 4716
else
yy = c - 4715
return sprintf(&quot;%4d %02d %02d&quot;, yy, mm, dd)
}

#----------------------------------------------------
# Convert calendar to Julian date
#----------------------------------------------------

function JulDate(y, m, d, jd) {
if ((100.0 * y + m - 190002.5) < 0)
jd = 0.5
else
jd = 0.0
jd = 367.0 * y
jd -= int(7.0 * (y + int((m + 9.0) / 12.0)) / 4.0)
jd += int(275.0 * m / 9.0)
jd += d
jd += 1721013.5
return jd
}
#----------------------------------------------------
# Weekday of Julian date (0=Sunday)
#----------------------------------------------------

function WeekDay(jd) {
return (jd + 1.5) % 7
}

#----------------------------------------------------
# Convert calendar (mm/dd/yy) to julian date
#----------------------------------------------------

function GetJulianDate(cd, yy, mm, dd) {
mm = substr(cd, 1, 2)
dd = substr(cd, 4, 2)
yy = substr(cd, 7, 2)
if (yy < 100) {
if (yy <= 68)
yy += 2000 ;
else
yy += 1900 ;
}
return JulDate(yy, mm,dd)
}

#===================================================
# P A T T E R N S / A C T I O N S
#===================================================

#---------------------------------------------------
# Init ...
#---------------------------------------------------

BEGIN {
split(&quot;Sun-Mon-Tue-Wed-Thu-Fri-Sat&quot;,Wdays,&quot;-&quot;)
LastJulian = GetJulianDate(LAST)
FirstJulian = LastJulian - DAYS
}

#---------------------------------------------------
# Select lines : Date > LAST - DAYS
#---------------------------------------------------

{
Date = $1
Julian = GetJulianDate(Date)
Wd = Wdays[WeekDay(Julian)+1]
if (Julian > FirstJulian)
print Wd,$0
}
Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top