The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading Files In Pablo_beezo SUN Solaris 1 06-12-2008 11:21 AM
Reading Files oop UNIX for Dummies Questions & Answers 3 07-31-2007 08:40 AM
reading .bin files eastcoast_uix UNIX for Dummies Questions & Answers 1 06-26-2007 02:43 PM
reading gz files arushunter Shell Programming and Scripting 2 02-16-2007 06:29 PM
Reading *.chm files? riwa UNIX for Dummies Questions & Answers 3 04-02-2006 10:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-23-2008
Pablo_beezo Pablo_beezo is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 85
HELP!!!! Problem reading in files

HI,

I have wrote a script which reads in a file that has a list of files within it.

The script then searches the directory for these files and when found will output to an email with a layout table indicating the date of the file and an ok status if the file = todays date if not a waiting appears. (it is to show the recipient that they need to chase for the waiting files).

two of the files are todays date - jkl.csv and stu.txt the rest are either blank or not todays date.

The problem i have is that i cannot get the waiting / ok to work. The script below is outputting all files to warning when in fact all should be warning except jkl.csv and stu.txt???

script is:

#!/bin/ksh

###########
#VARIABLES#
###########

RUNREF=`date +%Y%m%d`
FILE_LIST="../parms/files.txt"
Subject="xxx File Check"
EMAIL="cdmspb"
MAIL_FROM="xxx"
LOG_DIRECTORY="../logs"
MSG_DEST="${LOG_DIRECTORY}/${RUNREF}_build.log"
argv0=`basename $0`
fsz=47
ul="-----------------------------------------------"
ck="+"
cs="|"

###########
#FUNCTIONS#
###########

writelogf()
{
if [ $# -gt 9 ]
then
printf "Unable to generate requested error line\n"
exit 1
fi

args=$#

case $args in
1) printf "$1" >&2;;
2) printf "$1" "$2" >&2;;
3) printf "$1" "$2" "$3" >&2;;
4) printf "$1" "$2" "$3" "$4" >&2;;
5) printf "$1" "$2" "$3" "$4" "$5" >&2;;
6) printf "$1" "$2" "$3" "$4" "$5" "$6" >&2;;
7) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" >&2;;
8) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" >&2;;
9) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" >&2;;
esac

case $args in
1) printf "$1" >>$MSG_DEST;;
2) printf "$1" "$2" >>$MSG_DEST;;
3) printf "$1" "$2" "$3" >>$MSG_DEST;;
4) printf "$1" "$2" "$3" "$4" >>$MSG_DEST;;
5) printf "$1" "$2" "$3" "$4" "$5" >>$MSG_DEST;;
6) printf "$1" "$2" "$3" "$4" "$5" "$6" >>$MSG_DEST;;
7) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" >>$MSG_DEST;;
8) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" >>$MSG_DEST;;
9) printf "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" >>$MSG_DEST;;
esac

}

get_time_stamp()
{
ts_time=`date +"%H:%M:%S"`
ts_date=`date +"%B %d %Y"`
}

start_msg()
{
get_time_stamp
writelogf "\n$MSG search initiated at $ts_time on $ts_date\n\n"
}

end_msg()
{
get_time_stamp
writelogf "\n$MSG search completed at $ts_time on $ts_date\n"
}


email_user()
{
#Email
mail -t "$1" << EOF
Subject: $3
From: $2
$4
$5
EOF
}


#############
#MAIN SCRIPT#
#############

STATUS="OK"

MSG="Waiting for xxx files"
start_msg $STEP $MSG

writelogf "$argv0:+%-${fsz}.${fsz}s-%-${fsz}.${fsz}s-%-${fsz}.${fsz}s+\n" $ul $ul $ul
writelogf "$argv0:|%-${fsz}.${fsz}s${cs}%-${fsz}.${fsz}s${cs}%-${fsz}.${fsz}s${cs}\n" "FILE" "DATE" "STATUS"
writelogf "$argv0:|%-${fsz}.${fsz}s${ck}%-${fsz}.${fsz}s${ck}%-${fsz}s|\n" $ul $ul $ul

while read FILE
do
file_date=`ls -l $FILE | nawk 'BEGIN {FS=" "}{ printf "%s %s\n", $6, $7}'`

MONTH=`date +"%b" | cut -d" " -f1`
DAY=`date +"%e" | nawk '{ printf "%d\n", $0}'`
todays_date="$MONTH $DAY"

if [[ ( "$FILE" == " " ) || ( ! -r $FILE ) || ( $file_date != $todays_date ) ]]
then
STATUS="WAITING"
fi
#echo "file [$FILE] [$STATUS]"

writelogf "$argv0:|%-${fsz}.${fsz}s${cs}%-${fsz}s${cs}%-${fsz}s${cs}\n" $FILE "$file_date" $STATUS

done < $FILE_LIST

writelogf "$argv0:+%-${fsz}.${fsz}s-%-${fsz}.${fsz}s-%-${fsz}.${fsz}s+\n" $ul $ul $ul

end_msg $STEP $MSG

#email all users
mailx -r $MAIL_FROM -s "xxxx File Check" $EMAIL < $MSG_DEST

rm $MSG_DEST



output email is below:


Code:
Waiting for xxxx files search initiated at 10:55:40 on June 23 2008

test3.sh:+-----------------------------------------------------------------------------------------------------------------------------------------------+
test3.sh:|FILE                                           |DATE                                           |STATUS                                         |
test3.sh:|-----------------------------------------------+-----------------------------------------------+-----------------------------------------------|
test3.sh:|/abc.txt  |Jun 19                                         |WAITING                                        |
test3.sh:|/def.out  |Jun 19                                         |WAITING                                        |
test3.sh:|/ghi.dat  |Jun 19                                         |WAITING                                        |
test3.sh:|/jkl.csv  |Jun 23                                         |WAITING                                        |
test3.sh:|/mno.txt  |Jun 11                                         |WAITING                                        |
test3.sh:|/pqr.dat  |Jun 11                                         |WAITING                                        |
test3.sh:|/data/stu.txt  |Jun 23                                         |WAITING                                        |
test3.sh:|/vw.dat   |                                               |WAITING                                        |
test3.sh:|/xy.dat   |                                               |WAITING                                        |
test3.sh:|/z11.dat  |                                               |WAITING                                        |
test3.sh:+-----------------------------------------------------------------------------------------------------------------------------------------------+

Waiting for xxxxx files search completed at 10:55:41 on June 23 2008


Last edited by Yogesh Sawant; 06-23-2008 at 08:22 AM.. Reason: added code tags
  #2 (permalink)  
Old 06-23-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is online now Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,993
moved to "scripting" cause not a solaris problem...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0