LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-26-2012, 06:10 PM   #1
kevinyeandel
Member
 
Registered: Jun 2008
Posts: 49

Rep: Reputation: 16
bash - how to achieve a test -d on list of file paths


Hello

If I execute:

echo -e "set pagesize 0 \n select file_system_path from dm_location_s;" | sqlplus -s user/pass@schema | grep ^\/

I get back a load of file paths:

/data/dev_store/dev/content_storage_01
/opt/documentum/dba/log
/opt/documentum/dba/config
/opt/documentum/dba
/opt/documentum/dba/auth
/opt/documentum/dba/secure/ldapdb
<snip>

What I want to do is append to my command a 'test -d' type of thing so I can determine that each of the file paths actually exists. I need to do it as a single line and was looking for some sort of solution, e.g like -exec test -d {} \;

Could someone suggest how I can achieve this?

Many thanks in advance.

Kevin
 
Old 05-26-2012, 07:48 PM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Assuming you use Bash:
Code:
printf 'set pagesize 0\nselect file_system_path from dm_location_s;\n' | sqlplus -s user/pass@schema | while read item ; do [ "${item:0:1}" = "/" ] && [ -e "$item" ] && echo "$item" ; done
This outputs only those lines that begin with a slash and exist in the filesystem.

Note that -e only tests for existence; it does not care what it is, or whether it is readable, writable, or executable. -d would test the existence of a directory. See man 1 test for detailed descriptions of the various possible tests.
 
1 members found this post helpful.
Old 05-28-2012, 07:32 AM   #3
kevinyeandel
Member
 
Registered: Jun 2008
Posts: 49

Original Poster
Rep: Reputation: 16
Thanks for getting me over the hurdles on this NA. I managed to get it all into one (long, long) line, pull out the data and put it into xml format.
I can see already I could make the line a bit shorter but this will do!

Kevin

Code:
echo "<locations>" ;printf 'set feedback off \n set pagesize 0\n set linesize 300\n select file_system_path from dm_location_s;\n' | sqlplus -s user/pass@schema | while read item ; do  [ "${item:0:1}" = "/" ] && df -P -h "$item" | sed -e 1d|head -3 | awk -v ITEM=$item '{print " <location>\n  <name>" ITEM "</name>\n  <max>" $2 "</max>\n  <avail>" $4 "</avail>\n  <used>" $3 "</used>\n  <pc>" $5 "</pc>\n </location>\n"} END { } ' ; done ; echo "</locations>"
Output
Code:
<locations>
<location>
<name>/data/nas_store/repo/content_storage_01</name>
<max>350G</max>
<avail>86G</avail>
<used>265G</used>
<pc>76%</pc>
</location>

<location>
<name>/opt/documentum/dba/log</name>
<max>15G</max>
<avail>1.4G</avail>
<used>13G</used>
<pc>91%</pc>
</location>
<snip>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash script] What does this mean? -- FILE=${LIST##*/} thomas2004ch Linux - Software 1 03-05-2012 07:21 AM
Bash test if pattern match of file exists bioinformatics_guy Linux - Newbie 4 04-17-2009 06:42 AM
Bash - File paths into an array Bat17 Programming 5 10-31-2006 03:56 AM
bash file test - newline is a directory? haxcess Linux - General 2 03-26-2006 11:34 AM
bash script test file operators... bulliver Programming 3 10-17-2003 12:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration