Error to "find" a matching array element in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error to "find" a matching array element in a directory
# 1  
Old 09-30-2008
Error to "find" a matching array element in a directory

Hi,
I have defined an array which holds a couple of elements which are nothing but files names. I want to find the files in a directory for the matching file name(array elements) with less than 1 day old.
When I am trying to execute the code (as below), it gives an error.

Your help in this regard is solicited.

#!/bin/ksh
#########################################################################
# Mainline Section #************************************************************************
# Name: dailyjobcheck.ksh
#************************************************************************
RETCD="Return-Code= 0"
DATADIR=/usr1/MKB333/test
BPRDDIR=/app301/MKBTEST611/BPRD; export BPRDDIR
set -A bprdArr tibpsext tibjelvj tibjechk tibjevt2 wmsbxtvx tibapepr.log cisbworm
cntB=0
echo "Job ran on `date +"%m/%d/%Y"` " >>$DATADIR/test
echo "Statistics: \n" >>$DATADIR/test

while [ $cntB -le ${#bprdArr[@]} ]
do
FILE=`find $BPRDDIR -type f -mtime -1 -name "`echo ${bprdArr[cntB]}`*"`
if [ -f $FILE ];
then
RC=`awk '/Return-Code= 0/ { print $5,$6 }' | $FILE`
if [ "$RC" = "$RETCD" ]
then
echo "`echo ${bprdArr[cntB]}` ran OK on `date | cut -c1-3`day" >>$DATADIR/test
else
echo "`echo ${bprdArr[cntB]}` Abend \n" >>$DATADIR/test
fi
else
echo "`echo ${bprdArr[cntB]}` did not run on `date | cut -c1-3`day" >>$DATADIR/test
fi
cntB=`expr $cntB + 1`
done
----------------------------------------------------------
ERROR
----------------------------------------------------------
dailyjobcheck.ksh[41]: dailyjobcheck.ksh: cannot execute
find: The -name option requires filename argument.
dailyjobcheck.ksh[41]: tibpsext: not found
dailyjobcheck.ksh[42]: test: arg
ument expected
---------------
---------------

Regards,
Ketan
# 2  
Old 09-30-2008
You probably mean

Code:
FILE=`find $BPRDDIR -type f -mtime -1 -name "${bprdArr[$cntB]}*"`

... with the missing dollar sign for the subscript, and the silly echo in backticks removed.

The code seems to assume there is only a single matching file.

Why don't you simply do

Code:
for base in ibpsext tibjelvj tibjechk tibjevt2 wmsbxtvx tibapepr.log cisbworm; do
  ...

seeing as you don't seem to be using the numeric index for anything explicitly?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected: $ find . -iname "*.PDF" $ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \) $ find . -path "*_nobackup*" -prune -iname "*.PDF" They all returned the match: ./folder/file.pdf :b: This find returned no matches: $ find . -path "*_nobackup*" -prune... (3 Replies)
Discussion started by: wolfv
3 Replies

3. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

4. UNIX for Dummies Questions & Answers

"-maxdepth 1" argument for Solaris find. Other way to restrict find in only one directory?

Hi I wish to find only files in dir /srv/container/content/imz06/. It means exclude subfolder /srv/container/content/imz06/archive/ > uname -a SunOS testbox6 5.10 Generic_139555-08 sun4v sparc SUNW,Sun-Blade-T6320Its Solaris default "find" > find /srv/container/content/imz06/* -name... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

5. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

6. Programming

C: Initialize "const" array from the "heap"

Hello, I am working on solving an NP-Complete problem, so it is very important that operations and data with limited integer-argument ranges be computed using immutable look-up-tables contained entirely in CPU cache. Retrieval of the look-up-table data must never leave the CPU once initially... (6 Replies)
Discussion started by: HeavyJ
6 Replies

7. Shell Programming and Scripting

Delete files older than "x" if directory size is greater than "y"

I wrote a script to delete files which are older than "x" days, if the size of the directory is greater than "y" #!/bin/bash du -hs $1 while read SIZE ENTRY do if ; then find $1 -mtime +$2 -exec rm -f {} \; echo "Files older than $2 days deleted" else echo "free Space available"... (4 Replies)
Discussion started by: JamesCarter
4 Replies

8. Shell Programming and Scripting

Results of "find" to an array

I am looking to search a directory for a folder or file and when it finds any hits I want it to store those hits in an array so I can work with those hits later on. I have been trying to do something like this but it isn't putting results into an array like I would like, is it syntax or is this... (8 Replies)
Discussion started by: tret
8 Replies

9. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies

10. Shell Programming and Scripting

acessing awk array element while getline < "file"

I am attempting to write a awk script that reads in a file after awk array elements are assigned and using those elements while reading in the new file. Does this make sense? /pattern/ {tst=$3} (( getline < "file" ) > 0 ) { x=x " "tst } When I print tst in the END statement it... (9 Replies)
Discussion started by: timj123
9 Replies
Login or Register to Ask a Question