![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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() { 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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|