Computing.Net > Forums > Unix > Syntax problem with find cmd in scr

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Syntax problem with find cmd in scr

Reply to Message Icon

Name: MaureenT
Date: July 18, 2008 at 21:35:42 Pacific
OS: AIX 5.3, Solaris 8, Redha
CPU/Ram: mixed
Product: mixed
Comment:

trying to provide a list of locations to search using find for files that have been modified in last 24 hrs. Can get appropriates results running manually but not in script. I've tried a few different syntaxes but not hitting the right one.

Here's part of the code:
#!/bin/ksh

while read LINE
do
echo $LINE
find /$LINE -type f -mtime -1 -exec ls -al {} \; >/$OUTFILE
done <$INFILE

The input file only lists directory names without the leading slash (ie. home). I'm trying to get this to run for local disk and SAN attached disk. Also need it to run on AIX 5.3, Solaris 8 and Redhat 4. It is reading the input file correctly and echoing the lines. It also creates the output file correctly. Seems to read local but not SAN attached disk. Am I missing a switch to follow links? tried -follow

On Solaris it runs slow like it's reading SAN drives but doesn't produce any results even for local disk. On AIX, it skips past SAN drives quickly and produces results on local disk.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: July 19, 2008 at 10:40:24 Pacific
Reply:

First, are you sure that you have write permissions on this file?

/$OUTFILE

Second, if any of your directory objects contain spaces, you probably need to use double quotes around $LINE:

find "/$LINE" -type f -mtime -1 -exec ls -al {} \;

Also, spaces in the directory names or files could cause you other problems. Take a look at this column:

http://www.unixreview.com/documents...

(It also discusses using xargs instead of find's -exec)

third, consider checking that the directory exists before executing the find:


if [ -d "/${LINE}" ]
then
find ...
fi



0

Response Number 2
Name: MaureenT
Date: July 20, 2008 at 12:43:01 Pacific
Reply:

definitely have write permissions on $OUTFILE. Running as root and the script creates that file so created as same user.

no spaces in the directories.
And the directories definitely exist. $INFILE is manually created unique to each server to list the file systems that want to search.

I'm probably running into a shell problem. Tried doing a which find and forcing to use the same find cmd. ie THISFIND=/usr/bin/find.
Also tried changing script to bash...
Just one of those things that's driving me nuts.
Thanks for feedback though.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Syntax problem with find cmd in scr

Problem with find script www.computing.net/answers/unix/problem-with-find-script/5357.html

problem with grep in a for loop www.computing.net/answers/unix/problem-with-grep-in-a-for-loop/3967.html

problems with unix file system www.computing.net/answers/unix/problems-with-unix-file-system/7541.html