- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2003 03:43 AM
12-09-2003 03:43 AM
find script
We would like to script a find file search, currentlyhave a file containing a list of files & want to do a
"find" for the file and to out put that the file was found and is in x directory. The script must also
cater for files not found. Any ideas would be most appreciated.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2003 03:51 AM
12-09-2003 03:51 AM
Re: find script
for i in `cat input_file`
do
find /dir_where_to_find -name $i
if [$? -eq 0]
then
echo $i >> /tmp/found_files.txt
else
echo $i >> /tmp/file_not_found.txt
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2003 04:01 AM
12-09-2003 04:01 AM
Re: find script
Thanks for the info, we have used that but what if we dont no the search directory? How would do a global search, if the file is found then the output to be redirected to log file saying ie. "$file found in directory_name"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2003 04:09 AM
12-09-2003 04:09 AM
Re: find script
for i in `cat input_file`
do
find / -depth -name $i -print -exec echo {} >> /tmp/files.txt
if [$? -eq 0]
then
echo $i >> /tmp/found_files.txt
else
echo $i >> /tmp/file_not_found.txt
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2003 04:09 AM
12-09-2003 04:09 AM
Re: find script
for i in `cat input_file`
do
find / -name $i >> /tmp/found_files.txt
if [$? -ne 0]
echo $i >> /tmp/file_not_found.txt
fi
found_files will contain full pathname & filename.
regards,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2003 04:11 AM
12-09-2003 04:11 AM
Re: find script
for i in `cat input_file`
do
find / -name "$i" > /tmp/found_files.tmp
if [$? -eq 0]
then
echo "FOUND:$i"
cat /tmp/found_files.tmp
else
echo "FAILED TO FIND:$i"
fi
done >> /tmp/results.txt
Strictly, if run with privilege, e.g. as root, you should avoid predictable names in shared directories in case some malicious person creatred /tmp/results.txt as a symbolic link to something important, e.g. /etc/fstab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2003 05:45 AM
12-09-2003 05:45 AM
Re: find script
#!/usr/bin/perl
$startdir="/";
open(INP,"
close(INP);
$lastdir=$startdir;
open(LS,"ls -1R $startdir|");
while(
chomp;
next unless $_;
if (substr($_,0,1) eq "/") { $lastdir=$_; }
else {
push(@{$names{$_}},$lastdir) if $names{$_};
}
}
close(LS);
foreach $name (sort keys %names) {
$dirs=$names{$name};
if (scalar @$dirs) {
print $name," ",join(",",@$dirs),"\n";
} else {
print $name," NOT FOUND...\n";
}
}
HTH
-- Rod Hills