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
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

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 05-20-2008
Testing_Yorsh Testing_Yorsh is offline
Registered User
  
 

Join Date: May 2008
Posts: 1
Question Checking Files with a Shell Script

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 !
  #2 (permalink)  
Old 05-20-2008
unSpawn unSpawn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 53
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

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 09:08 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