how to exit with success if the file is not found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to exit with success if the file is not found
# 1  
Old 05-09-2007
how to exit with success if the file is not found

I want to put a exit if there is no file found.
In the directory I can have multiple txt files with EPISGCHGS as prefix or maynot have one.

When I am trying the following it is erroring if there is no text file with the EPISGCHGS as prefix.

for file in EPISGCHGS*.txt
do
cat $file > ultisource.txt
done

Thanks in advance.
# 2  
Old 05-09-2007
Try:
if [ -r EPISGCHGS*.txt ]
then
for file in EPISGCHGS*.txt
do
cat $file > ultisource.txt
done
else
echo no files found
fi

See manual page for test
If there is more than one input file ultisource.txt will only contain the last file found, if you want it to contain all of the files then you should change the cat line to cat $file >>ultisource.txt
# 3  
Old 05-10-2007
Thanks.But I am getting error.
It is erroring for : binary operator expected on the
if [ -r EPISGCHGS*.txt ] line.
Any suggestions?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file if not found send mail if exit call second script

I need to check my script and change to working mode. currently it was not sending the mail and exit without calling the second script. I need to check the file is present ="/home/Rvtools/test.csv" if this file not found after the time retry send mail file not found If the file exit run the... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

2. UNIX for Advanced & Expert Users

Executing a job with file success

Hello All, I have a scenario where I need suggestion I am creating a file watcher job on autosys and and command job to do a SCP a file from one server to another. My file watcher will get success once the file get receive. The file I am receiving a zip file. THe command job which I am... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

3. UNIX for Dummies Questions & Answers

Find exit with success with non executable directory

Hi there, I'm quite surprised by the following behavior of find. $ find -ls # I have a directory and a file in it 8145 4 drwxr-xr-x 3 me me 4096 May 10 09:36 . 87 4 drwxr-xr-x 2 me me 4096 May 10 09:36 ./dir 88 0 -rw-r--r-- 1 me me 0... (2 Replies)
Discussion started by: chebarbudo
2 Replies

4. UNIX for Dummies Questions & Answers

Execute shell script and if string found while executing then exit

Hi All, I have one shell script start.sh which executes another shell script test.sh something like below :test.sh -param1 -param2 In the test.sh there is one command for removing file:rm file1.bak I want whenever I execute start.sh, it will execute test.sh and if it finds string rm... (7 Replies)
Discussion started by: ORAI
7 Replies

5. Shell Programming and Scripting

Logging success event into file

Hi, I've the following code to log the errors any after the command is executed. # Ksh 88 Version log_path=/home/etc/fls/fls_log.log del_path=/home/etc/fls/to_day rm $del_path/* >> $log_path 2>&1 But I even want to log if the rm command is success without any error along with... (1 Reply)
Discussion started by: smile689
1 Replies

6. Shell Programming and Scripting

awk with exit status if pattern not found

Hi everyone, Looking at writing another awk program here to find a pattern on a text file. If patterns aren't found I want the awk program to exit and then bash to file a failure log on the local machine. Then later a management framework we have in place will read if that failure log file... (3 Replies)
Discussion started by: Zaphod_B
3 Replies

7. Shell Programming and Scripting

How to write SCP success or failure to a file

Does anyone know how to write the results (success and failure) to a file. I am using TCSH on a Solaris machine. I have the following code for a successful SCP...could someone help me add to this so it caputres failures also? CODE SO FAR (received from a previous post): scp sourcefile.txt... (3 Replies)
Discussion started by: thibodc
3 Replies

8. Shell Programming and Scripting

Curl ftp upload success but no file exist on the server !!!!

hello, I'm trying to upload a file to this ftp server and others ftp://ftp.byethost12.com as you can see in the output of CURL using the -v option curl reports that the upload succeeded but when i connected to the server with file-zilla there is no file uploaded the same command upload files... (5 Replies)
Discussion started by: laraaj
5 Replies

9. Shell Programming and Scripting

NDM process say success but file didn't reach destination

I am using ndmcli to NDM my files. When i do so it prints success for the process, with out any errors, but file is not reached at destination. ndmcli -x << EOJ submit phcdb process snode=$RMT_NODE_NAME step01 copy from (file=$SRC_FILE_NAME pnode) to (file=$DST_FILE_NAME snode... (0 Replies)
Discussion started by: pattamuthu
0 Replies

10. UNIX for Dummies Questions & Answers

Checking the header and trailer for a given string and if not found, exit out of the

hi, How to check a given file for a string and if it's not found, exit out ofthe script? e.g. a file Test123 is there whose header begins with #bt and trailer begins with #ed. I have to check if the header and trailer matches as above and if not, exit out of the script. How can we do it in... (2 Replies)
Discussion started by: er_ashu
2 Replies
Login or Register to Ask a Question