if [ -d /Users/Shared/Active Jobs ];
then
Echo "<result>Du -hs /Users/Active Jobs | awk '{print $1}'
</result>
Else
Echo "<result>Not found</result>"
fi
The -d flag in the if statement checks for the presence of a directory. If
that directory exists, execute this block of code. Otherwise, skip over
and just echo a result that it wasn't found.
j
--
Jared F. Nichols
Desktop Engineer, Client Services
Information Services Department
MIT Lincoln Laboratory
244 Wood Street
Lexington, Massachusetts 02420
781.981.5436
built in function if bash
if [[ -e /path/to /folder ]]
This would be if it exists
if [[ -!e /path/to/folder ]]
This would be, if does not exist
Thanks Guys for the quick replies!
--
James Fuller | Starbucks Coffee Company | Technology Application Services
| application developer II | Coffee Master
E: jafuller at starbucks.com | V: 206.318.7153 | F: 206.318.0155
The only difference betwee -e and -d is that -e will check if it exists regardless of what it is and -d expects it to be a directory. So, if -d points to a file and not a directory it will fail. Otherwise either method works
Adding to this a bit:
On 1/19/11 11:49 AM, "Thomas Larkin" <tlarki at kckps.org> wrote:
-d tests that an item exists and is a directory
-e tests that an item exists and is a file or directory
-f tests that an item exists and is a file
--
William Smith
Technical Analyst
Merrill Communications LLC
(651) 632-1492
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
pretty much sums up all your options, but do note that conditional statements can only process one thing at a time. So, if you need to test a set of paths you would need to create an array of paths or a loop that would output all your paths you wanted to check.
how would we convert that to a number where it joins a smart group based on file size?
Make sure the Extension Attribute (EA) is defined as returning an Integer. Add a tail
to only get the last line, in case that directory ever somehow ends up with any subdirectories, and sed 's/.$//'
to remove the last character (sorry, my awk-fu is not great when I haven't had much coffee):
du -H /path/to/your/dir | awk 'END { print $1 } ' | sed 's/.$//'
(someone who is slightly awake, please consolidate that awk
for me)
Then, create a Smart Group > Show Advanced and choose that EA, and from there you can use More Than as an operator. (If More Than/Less Than are not available, go back and edit the EA's Data Type.)