Return a message when a file is not found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Return a message when a file is not found
# 1  
Old 09-07-2007
Return a message when a file is not found

Hi there,

I am writing a script to look for tmp log files that have not been access within the last 10 days.

I am using the follwing command within the script:

find /var/tmp -name *log -atime -9 ¦xargs

What I would like to be able to do would be to display a message if there is no files listed..

How would I go about this

(I am new to Unix and scripting)

Rgds
Colin
# 2  
Old 09-07-2007
Message if no files found

Normally this is tested by checking the exit status of the find command. In general, unix commands return a 0 (zero) status is all is well. I am not absolutely certain here but I believe that if your find command fails (IE does not find any files) the all is 'not well' and it will not return 0.
So....

find /var/tmp -name *log -atime -9 ¦xargs
if [[ $? -ne 0 ]]; then
echo error message
fi

$? holds the return status of the immediately preceding command.
Note that 'echo error message' is *not* real scripting - just pseudo-code
# 3  
Old 09-08-2007
Quote:
Normally this is tested by checking the exit status of the find command. In general, unix commands return a 0 (zero) status is all is well. I am not absolutely certain here but I believe that if your find command fails (IE does not find any files
)

Even if the file is not found the exit status will always be zero for
Quote:
find /var/tmp -name *log -atime -9 ¦xargs
you can try,

Code:
FINDVAL=`find /var/tmp -name *log -atime -9 | wc -l`
if [[ $FINDVAL -eq 0 ]]
then
echo file not found
fi

Any specific reason for using xargs with find command here ??

Cheers,
K
kamitsin
# 4  
Old 09-08-2007
When I try to use the code above I get the error message:

find path-list [predicate-list]

On the using the xargs with the find command it was the way that I was shown to write the command..

As I have sayed I am new to Unix..also I am using HP-UX

Rgds

Colin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to find a file based on pattern & return the filename if found?

Hi all, I am a newbie here. I have this requirement to find a file based on a pattern then return the filename if found. I created a script based on online tutorials. Though, I am stuck & really appreciate if anyone can have a quick look & point me to the right direction? #Script starts... (10 Replies)
Discussion started by: buster_t
10 Replies

2. Shell Programming and Scripting

How to return a message after command runs?

I have a script like this: echo "enter filername in lowercase" read -e filername exec 2>&1 echo "type the start date in format MM/DD/YYYY" read -e startdate exec 2>&1 echo "enter the end date in format MM/DD/YYYY" ... (2 Replies)
Discussion started by: newbie2010
2 Replies

3. Shell Programming and Scripting

awk Help -- If match found return the count

Hi All, I need to get the count of records in the file, if the passing parameter matches with the list of records in the file. Below is my example source file: Test1.dat 20120913 20120913 20120912 20120912 20120912 20120912 20120912 20120913 20120913 20120912 In my script I am... (5 Replies)
Discussion started by: bbc17484
5 Replies

4. Shell Programming and Scripting

not found message

I am trying to execute a script called tfile.sh in a bash shell in solaris and it throws up the following message I am getting the required output after this message. How do i get the message to disappear. Can someone please point out my mistake in the script? Thanks in advance ... (13 Replies)
Discussion started by: goddevil
13 Replies

5. Shell Programming and Scripting

not found message

I am executing the following script in a bash shell in solaris and it throws up the following message : But i get the output that i require nevertheless. Can anyone please spot what is causing the warning and how do i get it go away? VAR1="e6842w2334f76figtl5.systems.grp" if 76fig`... (2 Replies)
Discussion started by: goddevil
2 Replies

6. Shell Programming and Scripting

why the message not found in the file

Hi, I am a newbie for shell programming and met some question about redirect output to a file. See the details. #!/usr/bin/sh ... ./doSomething.pl >> RAW_DATA echo "testing is done !" >> RAW_DATA Descirption: doSomething.pl do a bit complex things and output some message. I append... (3 Replies)
Discussion started by: programmerBegin
3 Replies

7. Shell Programming and Scripting

Function not found message

I have shell script as below: #!/bin/ksh #set -xv function set_variable { VARIABLE_NAME=$1 CURRENT_PATH=`pwd` if ; then echo "\nconfiguration_file.lst file not found in $CURRENT_PATH/common/common_scripts" exit 1; fi VARIABLE_COUNT=`cat... (2 Replies)
Discussion started by: findprakash
2 Replies

8. Shell Programming and Scripting

Scripting problem - when the file is not found i want it to return to the menu

when the file is not found i want it to return to the menu, however it carries out the next line when i hit a key I know its probably something simple can anyone help? here is my pause function: function pause(){ read -s -n 1 -p "Press any key to return to Menu . . ." echo } SCRIPT... (2 Replies)
Discussion started by: Alendrin
2 Replies

9. UNIX for Dummies Questions & Answers

Return mail message

Hi I would like to know how interpret line by line a return mail message sent by unix mailer-daemon (2 Replies)
Discussion started by: alcvrjo
2 Replies

10. Shell Programming and Scripting

How to scan a file for literal, return 0 or 1 if found?

How can i scan a file in a UNIX script and look for a particular keyword? For example if i wanted to scan the file "lpcmp165.out" and see if it contains the term "error" or "ERROR" and then return a 0 or 1 or some indicator as such? Detail example: sqlplus -s xx/yyyyyyy#@zzz <<EOF >... (11 Replies)
Discussion started by: bobk544
11 Replies
Login or Register to Ask a Question