HELP!!!! Problem reading in files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HELP!!!! Problem reading in files
# 1  
Old 06-23-2008
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  
Old 06-23-2008
moved to "scripting" cause not a solaris problem...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

[Solved] Problem with fork() while reading files

Good evening everyone. I have my finals and I'm facing a problem: I have a for cycle that is supposed to fork 2 children but somehow it forks only the first one. What am I doing wrong ? #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h>... (5 Replies)
Discussion started by: pfpietro
5 Replies

2. UNIX for Dummies Questions & Answers

Problem with fork() while reading files

Good evening everyone. I have my finals and I'm facing a problem: I have a for cycle that is supposed to fork 2 children but somehow it forks only the first one. What am I doing wrong ? #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h>... (1 Reply)
Discussion started by: pfpietro
1 Replies

3. Shell Programming and Scripting

Problem in reading the input value

echo "Enter the Value : " read value sed '1s:\(.\{6\}\)\(.\{4\}\):\1'$value':' flextran$RUN_DATE-completed.txt > temp.txt mv temp.txt flextran$RUN_DATE-completed.txt on the run time after entering the input value it waits for keystroke and the values is not input to the function The output... (4 Replies)
Discussion started by: rammm
4 Replies

4. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

5. Shell Programming and Scripting

Reading expression problem

I want to read a file -line by line which consists of the following statements Chr18:4000-4010 Chr20:4020-4030 Chr15:8000-8050 Pls. give a expression to read the line like this from a file Chr18:4000-4010 the given two replies reading like that Chr18:-10 but it is important to... (2 Replies)
Discussion started by: hravisankar
2 Replies

6. UNIX and Linux Applications

data reading problem..

In LVM I have one volume grp and it has two logical volumes A and B and both are full,so I extended my volume grp to 1GB with another hard disk and add this space to A and put my resr data .Now problem is that I get data from first hard disk only but I m unable to find data which is in second hard... (0 Replies)
Discussion started by: Rahul chauhan
0 Replies

7. Shell Programming and Scripting

Problem with reading characters

Hello, if I try this (in bash): #!/bin/bash cat leercaracter.sh | while read linea do # read character by character echo $linea | while read -n 1 caracter do echo $caracter done done New lines, spaces, tabs aren't showed by echo. How can I 'echo' those characters?... (7 Replies)
Discussion started by: albertogarcia
7 Replies

8. Shell Programming and Scripting

problem in reading a file

i need to read record by record i use script #!/bin/ksh for i in 'cat filename' do echo $1 done but i dont get expected result i just get filename echoed on screen (4 Replies)
Discussion started by: er_zeeshan05
4 Replies

9. UNIX for Advanced & Expert Users

problem with socket reading

I am not able to receive the message on socket in the current process when its waiting for its child to exit. code looks something like below //in one thread of the current process //thread 1 =============================================== int numBytes = read(sockid,buf,SIZE); //Now the... (2 Replies)
Discussion started by: swap007
2 Replies

10. Shell Programming and Scripting

help me ...problem in reading a file

hi, while reading a file line by line # name of the script is scriptrd while read line do echo $line done while executing bash$ ./scriptrd if i give the input as * the output is like it displays the contents of the current directory i jus wanted it to print as * (6 Replies)
Discussion started by: brkavi_in
6 Replies
Login or Register to Ask a Question