Search for multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search for multiple files
# 1  
Old 10-03-2016
DB Search for multiple files

I need to look for 3 files in a particular directory, if they are > 0kb. If files exist proceed further, if not mail out saying one of the file is missing. All the 3 files should be present.

Please see my script below and correct if needed. Anyway, it is not working.

Code:
#! /bin/bash
receipient=someone@alibaba.com
if [[ -s app/reps/File1.txt && -s app/reps/sample2.txt && -s app/reps/temp3.txt]]; then

tr -d '\032' < /app/reps/File1.txt >  /app/reps/File1_tmp.txt
tr -d '\032' < /app/reps/sample2.txt >  /app/reps/sample2_tmp.txt
tr -d '\032' < /app/reps/temp3.txt >  /app/reps/temp3_tmp.txt

fi
mailx -s "All the 3 files are available " $ receipient
exit 0

else

mailx -s "one of the file is missing" $ receipient
exit 1


Last edited by Scrutinizer; 10-03-2016 at 04:47 PM.. Reason: code tags
# 2  
Old 10-03-2016
  • The first paths are missing a leading /
  • $ receipient : the space behind the dollar sign should not be there
  • fi is in the wrong place
# 3  
Old 10-04-2016
Oracle

I made the changes as below:

Code:
#! /bin/bash receipient=someone@alibaba.com 

if [[ -s /app/reps/File1.txt && -s /app/reps/sample2.txt && -s /app/reps/temp3.txt]]; then
tr -d '\032' < /app/reps/File1.txt >  /app/reps/File1_tmp.txt
tr -d '\032' < /app/reps/sample2.txt >  /app/reps/sample2_tmp.txt 
tr -d '\032' < /app/reps/temp3.txt >  /app/reps/temp3_tmp.txt  
mailx -s "All the 3 files are available " $receipient
fi

exit 0  
else  mailx -s "one of the file is missing" $receipient
exit 1


The script has a permission of 770 (tried with 777 also) but I am getting the error saying that permission denied.

Can any one help me?


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 10-04-2016 at 11:38 AM.. Reason: Added CODE tags.
# 4  
Old 10-04-2016
WHEN do you get that error message? On which file? Please post a long file listing.

And, the fi still is in the wrong place!
# 5  
Old 10-04-2016
RedHat

Actually, I will be calling this FileCheck.sh from Informatica. To verify that script, I executed this script in putty as sh -v FileCheck.sh and I got the error message as Permission denied. I do not know, where to find the log file.

wondering, if the fi should come after the exit 1. Sorry, I am not sure, where it should be.

Last edited by rbatte1; 10-04-2016 at 12:09 PM.. Reason: Added ICODE tags
# 6  
Old 10-04-2016
one more,
Code:
if [[ -s /app/reps/File1.txt && -s /app/reps/sample2.txt && -s /app/reps/temp3.txt]]; then

has to be
Code:
if [[ -s /app/reps/File1.txt && -s /app/reps/sample2.txt && -s /app/reps/temp3.txt ]]; then

space between temp3.txt and ]].
# 7  
Old 10-04-2016
Try as
Code:
sh -vx FileCheck.sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with search and replacing multiple items in multiple files

Im having an issue when trying to replace the first column with a new set of values in multiple files. The results from the following code only replaces the files with the last set of values in val.txt. I want to replace all the files with all the values. for date in {1..31} do for val in... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

2. Shell Programming and Scripting

Pattern search multiple files

#!/usr/bin/ksh a="Run successfully" cd $APPS ls -l *.txt | while read $txt do if then cp $APPS/$txt cp $hist/$txt else rm $APPS/$txt echo "Files has been removed" fi done New in shell script please help me out Around 100 txt files in $APPS dir i want to search pattern from... (8 Replies)
Discussion started by: Kalia
8 Replies

3. Shell Programming and Scripting

Search and Replace in multiple files

Hello, I have hundreds of files in which I need to change email address. Here is what I am trying to do: 1. All text files are in a directory "a" 2. In the text file, I want to replace email address for preparer. All these lines start with {{PreparerEmail and end with }}. The email... (3 Replies)
Discussion started by: cartrider
3 Replies

4. Shell Programming and Scripting

search information in multiple files and save in new files

hi everyone, im stuck in here with shell :) can you help me?? i have a directory with alot files (genbank files ... all ended in .gbk ) more than 1000 for sure ... and i want to read each one of them and search for some information and if i found the right one i save in new file with new... (6 Replies)
Discussion started by: andreia
6 Replies

5. Shell Programming and Scripting

Search & Replace: Multiple Strings / Multiple Files

I have a list of files all over a file system e.g. /home/1/foo/bar.x /www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g. if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc. There... (2 Replies)
Discussion started by: spacegoose
2 Replies

6. Solaris

How to search for a word in multiple files

Hi, I want to find for a particular word which is existing in different files and folders under the parent directory. What command can I use to retrieve all the file names which is having the word. (1 Reply)
Discussion started by: rogerben
1 Replies

7. Shell Programming and Scripting

Search multiple patterns in multiple files

Hi, I have to write one script that has to search a list of numbers in certain zipped files. For eg. one file file1.txt contains the numbers. File1.txt contains 5,00,000 numbers and I have to search each number in zipped files(The number of zipped files are around 1000 each file is 5 MB) I have... (10 Replies)
Discussion started by: vsachan
10 Replies

8. Shell Programming and Scripting

Multiple search string in multiple files using awk

Hi, filenames: contains name of list of files to search in. placelist contains the names of places to be searched in all files in "filenames" for i in $(<filenames) do egrep -f placelist $i if ] then echo $i fi done >> outputfile Output i am getting: (0 Replies)
Discussion started by: pinnacle
0 Replies

9. Shell Programming and Scripting

Multiple search in multiple files

Hello, I would like to perform a search of several different strings in different files. I have the ouput of a unix command X which is for instance: aaa bbb ccc and I would like to look for each of these three strings into several files: file1 file2 etc. I have come up with a solution... (2 Replies)
Discussion started by: maxvirrozeito
2 Replies

10. UNIX for Dummies Questions & Answers

Search for files in multiple directories

I want to search for a file pattern in more than one directory. How I need to do that? Here is the scenario: I am having a directory structure like the following: /log ...../20051001 ..........ftp_server_20051001.log ..........ftp_down_server.log ..........ftp_up_server.log... (7 Replies)
Discussion started by: ravikirankethe
7 Replies
Login or Register to Ask a Question