The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 10:14 PM
script to search a file dr46014 Shell Programming and Scripting 1 02-28-2008 06:55 AM
Search File Script I4ce Shell Programming and Scripting 7 03-28-2006 02:12 PM
Search script BCarlson Shell Programming and Scripting 14 02-05-2006 02:50 AM
script to search all the directories abk Shell Programming and Scripting 3 07-10-2002 12:19 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 09-01-2007
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
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
  #2 (permalink)  
Old 09-02-2007
kamitsin's Avatar
kamitsin kamitsin is offline
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
  #3 (permalink)  
Old 09-04-2007
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
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
  #4 (permalink)  
Old 09-04-2007
xramm xramm is offline
Registered User
  
 

Join Date: May 2007
Posts: 113
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
  #5 (permalink)  
Old 09-05-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
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 !!
  #6 (permalink)  
Old 09-05-2007
xramm xramm is offline
Registered User
  
 

Join Date: May 2007
Posts: 113
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}'
  #7 (permalink)  
Old 09-05-2007
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
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 04:41 AM.. Reason: added note
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:33 AM.


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