The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Small Search script appu1987 Shell Programming and Scripting 2 06-03-2008 07:14 PM
script to search a file dr46014 Shell Programming and Scripting 1 02-28-2008 02:55 AM
Search File Script I4ce Shell Programming and Scripting 7 03-28-2006 11:12 AM
Search script BCarlson Shell Programming and Scripting 14 02-04-2006 10:50 PM
script to search all the directories abk Shell Programming and Scripting 3 07-09-2002 09:19 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-01-2007
Registered User
 

Join Date: Jul 2007
Posts: 99
Help with search script

HI all,

I am trying to find files that have .cc3 file extenstion folder using this script below, but this fails as there are files in the folder and i get a message saying i have no files. Please anyone reveiw and let me know if i am missing anything.I am working on this from two days and i don't know where i have gone wrote. I would be gratefull for any help on this

##!/usr/bin/sh -x
##Initialising variables

FROM_DIR=/disk1/sandeep/cc3/perry; export FROM_DIR
LOG_DIR=/disk1/sandeep/log/perry; export LOG_DIR

echo "COSTING CC3 FILE Check started........................................" > $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
cd $FROM_DIR

check=`ls|grep cc3|wc -l`

if [ $check -ne 0 ]

then
echo "INPUT FILE NOT FOUND FOR TODAY................................" > $LOG_DIR/errorperry.log
echo " " >> $LOG_DIR/errorperry.log
echo " " >> $LOG_DIR/errorperry.log
echo "Please verify the reason for the FAILURE....................." >>$LOG_DIR/errorperry.log
echo " " >> $LOG_DIR/errorperry.log
echo " " >> $LOG_DIR/errorperry.log
echo "EXITING FROM PROCESS..............................................................." >>$LOG_DIR/errorperry.log
cd $LOG_DIR
cat /disk1/stonehs1/log/perry/errorperry.log|mailx -s "ALERT-NO FILE FOUND" `cat maillist`
exit 1
else
echo "INPUT FILE FOUND FOR TODAY...................................." >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo "NUMBER OF RECORDS IN INPUT FILE STarts.............................." >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
wc -l *.cc3 >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
cat /disk1/stonehs1/log/perry/perry.log|mailx -s "ALERT-FILE FOUND" `cat maillist`
exit 0

thanks,
Sandeep
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-01-2007
kamitsin's Avatar
Registered User
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
Quote:
check=`ls|grep cc3|wc -l` #This will not work always because if a file exists with cc3 it will count that file also, what you need is the files with extension cc3.

if [ $check -ne 0 ] # if file exists the value of $check will not be null
then
echo "INPUT FILE NOT FOUND FOR TODAY................................" > $LOG_DIR/errorperry.log # it should be file found
echo " " >> $LOG_DIR/errorperry.log
echo " " >> $LOG_DIR/errorperry.log
echo "Please verify the reason for the FAILURE....................." >>$LOG_DIR/errorperry.log
echo " " >> $LOG_DIR/errorperry.log
echo " " >> $LOG_DIR/errorperry.log
echo "EXITING FROM PROCESS..............................................................." >>$LOG_DIR/errorperry.log
cd $LOG_DIR
cat /disk1/stonehs1/log/perry/errorperry.log|mailx -s "ALERT-NO FILE FOUND" `cat maillist`
exit 1
else
echo "INPUT FILE FOUND FOR TODAY...................................." >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo "NUMBER OF RECORDS IN INPUT FILE STarts.............................." >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
wc -l *.cc3 >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
echo " " >> $LOG_DIR/perry.log
cat /disk1/stonehs1/log/perry/perry.log|mailx -s "ALERT-FILE FOUND" `cat maillist`
exit 0
1) if unmatched - i am assuming that you have missed it while pasting the script.

2) problem with conditional statement logic.

if $check is not equal to zero then the file exists else does not exist.
You have put it otherway round so even if the file exist you will get the message file does not exist.

make it

Code:
if [[ $check -eq 0 ]]
or reverse the statements if the condition is true.

3) you would have been able to check the error yourself with the value of $check because you always had the debugging on in the script.

Cheers,
K
Reply With Quote
  #3 (permalink)  
Old 09-04-2007
Registered User
 

Join Date: Jul 2007
Posts: 99
Hi kamitsin,

I have made the change now and it is working. Thanks for your help . i would like to know how i can find the .cc3 files by making a change in this command in the script:

`ls|grep cc3|wc -l`

i tried changing it to `ls|grep *.cc3|wc -l`

but it did not work

Please let me know.

Thanks,
Sandeep
Reply With Quote
  #4 (permalink)  
Old 09-04-2007
Registered User
 

Join Date: May 2007
Posts: 111
Quote:
Originally Posted by bsandeep_80 View Post
Hi kamitsin,

I have made the change now and it is working. Thanks for your help . i would like to know how i can find the .cc3 files by making a change in this command in the script:

`ls|grep cc3|wc -l`

i tried changing it to `ls|grep *.cc3|wc -l`

but it did not work

Please let me know.

Thanks,
Sandeep
Code:
ls -al *.cc3|wc -l
Reply With Quote
  #5 (permalink)  
Old 09-05-2007
Registered User
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 187
You can use following one liner command to find the file of given name/ext.

find Directory -type f -name "*.CC3" -print

Directory could be fixed or given by the user.

Hope it would help !!
Reply With Quote
  #6 (permalink)  
Old 09-05-2007
Registered User
 

Join Date: May 2007
Posts: 111
Quote:
Originally Posted by xramm View Post
Code:
ls -al *.cc3|wc -l
as an alternative to get rid of size,date,owner data...

Code:
ls -al *.CC3|awk '{print $9}'
Reply With Quote
  #7 (permalink)  
Old 09-05-2007
manas_ranjan's Avatar
Registered User
 

Join Date: Jul 2007
Location: PUNE
Posts: 157
can you try this one,

check=`find . -type f -name "*.cc3" -print | wc -l`


NOTE: "." is the current dir , instead you can use your own search dir .

Last edited by manas_ranjan; 09-05-2007 at 01:41 AM. Reason: added note
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0