![]() |
|
|
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 |
| shell script for delete old files | krishnarao | Shell Programming and Scripting | 4 | 01-13-2009 04:33 AM |
| shell script for log files data! | rvrao77 | Shell Programming and Scripting | 6 | 11-30-2006 10:03 AM |
| checking exit status of a shell script | kdipankar | Shell Programming and Scripting | 2 | 05-09-2006 02:08 AM |
| Checking the valid paths in the shell script | srivsn | Shell Programming and Scripting | 3 | 12-28-2005 12:05 AM |
| shell script to find files | naren_samba2005 | Shell Programming and Scripting | 2 | 10-21-2005 06:06 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hey everyone, I'm writing a shell script that needs to loop thru a directory and check a defined type of files(.df). I use "checkfile.x" which is a compiled program to check those files. Sintaxis : checkfile.x DatefileName.df The program displays something like this: File: kanswer.df - start search File: kanswer.df has 1 records File: kaprvlmt.df - start search File: kaprvlmt.df has 72 records File: kapyhour.df - start search File: kapyhour.df - Last record is NOT a ZZZ record File: kapyhour.df has 90 records File: kaseitem.df - start search File: kaseitem.df has 173 records Here comes the catch, what I would like to do is, get the files with "Error" (we know if a file has an error buy checking the status for example the legend "Last Record not a ZZZ record" or "Error") and display them so the user will know which files nee do to be fixed. So if we continue working with the example included I should get something like this: File: kapyhour.df - start search File: kapyhour.df - Last record is NOT a ZZZ record And nothing else. Ok here is what I got so far: 1-Access the files in the directory 2-Check them with the "checkfile.x" program 3-Save the result on $FILE_W_ERR 4-Validate if there's one of the legends("Error" or "ZZZ"). 5-If true display the checkfile result else next record. Code:
# Goes thru the data files
for FILE in *.df
do
# Checks each of the files and stores the result
FILE_W_ERR=`checkfile.x $FILE`
#Looks for the Err message in the return value of checkfile
INSTR=`echo "$FILE_W_ERR" | egrep -c "ZZZ"`
# Validate if the checkfile found any errors
if [ "$INSTR" -ne "0" ]
then
# Display file with possible Error
echo $FILE_W_ERR
echo #INSTR
fi
done
This is returning this: File: kanswer.df - start search File: kanswer.df has 1 records File: kaprvlmt.df - start search File: kaprvlmt.df has 72 records File: kapyhour.df - start search File: kapyhour.df - Last record is NOT a ZZZ record File: kapyhour.df has 90 records File: kaseitem.df - start search File: kaseitem.df has 173 records The exact same result. I ran out of ideas here, please let me know if you have something I can use to get this done. Thanks in advance everyone ! |
|
||||
|
If you mean "display" as in "edit" you could for instance: Code:
#!/bin/bash
[ $# -eq 0 -o -d "$1" ] || { echo "${0//*\//}: dirname"; exit 1; }
find "$1" -type f -iname \*.df | while read FILE; do
# Results go to stdout, and
checkfile.x "${FILE}" 2>/dev/null
# ...provided "checkfile.x" uses proper exit codes, you could...
[ $? -eq 0 ] || vi "${FILE}"; wait
done
exit 0
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|