Posted on 06-26-2015 06:39 AM
Hello,
I need to gather Info on all " *.nsf files Lotus notes" on every mac. I want to be able to get full path, size, dates. They usually reside in /Users/Library/Application Support/IBM Notes Data/, but I want to do this for every user and then be able to run a report.
Is this something I should create an EA or policy with a script maybe both?
Thanks In advance.
Chris
Solved! Go to Solution.
Posted on 07-06-2015 12:59 PM
Hi @Chris.Lyons You can try the following script, which gathers the additional information on each file and drops it into an array. It keeps adding each file found along with the details into the array until its complete and then prints the results. The username and the path to each file are included in the results that the initial mdfind pulls, so there wasn't a need in my opinion to include that as separate information.
Since I don't have the specific Notes database files on my Mac, I can't test it against those types, but I did test it against other file types, like PDF, Pages, Word, etc.
#!/bin/bash
while read username; do
while read file; do
CDate=$(mdls "$file" -name 'kMDItemFSCreationDate' | awk '{print $3,$4}')
FSizeRaw=$(mdls "$file" -name 'kMDItemPhysicalSize' | awk '{print $3}' 2>/dev/null)
FSize=$((FSizeRaw / 1000))
## Add the above items into a running array
resulttmp+=("${file}:
Creation Date: $CDate
File Size: $FSize KB")
done < <(mdfind -onlyin /Users/$username -name 'kMDItemKind == "Notes database file" && kMDItemFSName == "*.nsf"')
done < <(dscl . list /Users UniqueID | awk '$2>500 {print $1}')
## If the array is not empty, print it as the result, respecting line breaks
if [[ "${resulttmp[@]}" != "" ]]; then
echo "<result>$(printf '%s
' "${resulttmp[@]}")</result>"
else
## Otherwise, print a 'None' result
echo "<result>None</result>"
fi
Hope it helps.
Posted on 06-26-2015 06:45 AM
I would think an EA would work, but as I have not used Lotus Notes in something like 10 years now, I can't really say for sure. But as long as you build the script correctly for the EA, it should be able to report on them across all user accounts on the Mac.
Posted on 07-06-2015 11:13 AM
Hello Mike,
Thanks for the reply. I have tried a few scripts but I am having trouble getting all the info from the files I am searching for here is what I have as my EA:
search=$( mdfind -onlyin /Users/ -name 'kMDItemKind == "Notes database file" && kMDItemFSName == "*.nsf"' )
if [ "$search" != "" ]; then
echo "<result>Yes
$search</result>"
else
echo "<result>No</result>"
fi
I get the file path but I want to be able to create a report with file name, file path, file creation date, file size as well.
I was hoping someone would have some ideas how to alter this to get what I need out of it. we only have Casper to work with to get the job done.
Thanks
Posted on 07-06-2015 12:59 PM
Hi @Chris.Lyons You can try the following script, which gathers the additional information on each file and drops it into an array. It keeps adding each file found along with the details into the array until its complete and then prints the results. The username and the path to each file are included in the results that the initial mdfind pulls, so there wasn't a need in my opinion to include that as separate information.
Since I don't have the specific Notes database files on my Mac, I can't test it against those types, but I did test it against other file types, like PDF, Pages, Word, etc.
#!/bin/bash
while read username; do
while read file; do
CDate=$(mdls "$file" -name 'kMDItemFSCreationDate' | awk '{print $3,$4}')
FSizeRaw=$(mdls "$file" -name 'kMDItemPhysicalSize' | awk '{print $3}' 2>/dev/null)
FSize=$((FSizeRaw / 1000))
## Add the above items into a running array
resulttmp+=("${file}:
Creation Date: $CDate
File Size: $FSize KB")
done < <(mdfind -onlyin /Users/$username -name 'kMDItemKind == "Notes database file" && kMDItemFSName == "*.nsf"')
done < <(dscl . list /Users UniqueID | awk '$2>500 {print $1}')
## If the array is not empty, print it as the result, respecting line breaks
if [[ "${resulttmp[@]}" != "" ]]; then
echo "<result>$(printf '%s
' "${resulttmp[@]}")</result>"
else
## Otherwise, print a 'None' result
echo "<result>None</result>"
fi
Hope it helps.
Posted on 07-07-2015 07:14 AM
This is great I have tried it out and it seems to be working, some systems seem not to be listing anything but I am wondering if spotlight is not functioning correctly..
But you script is awesome, I want to thank you for the help.....
Chris
Posted on 07-09-2015 05:43 AM
Thanks mm2270 this was very helpful, I have another question ok maybe 3. One is about how to manipulate the Array were should I look to learn more about how they are structured. The second question is it possible to have the info separated by tabs so when output it would be easier to separate in excel.
The last question is eventually they want to copy these files to a File share to convert them to MS Outlook files. What do you think is the best way to mount the file share ,collect these files and then copy to a file share, creating a folder labeled the computer then within that a folder with a user name then the files themselves.
Is that something that is possible with a script controlled by a policy in Casper or should this be a script that should run local on each device?
Again Thanks So Much for the help that worked like a charm.
Chris Lyons
Posted on 07-09-2015 08:19 AM
@Chris.Lyons You can learn more about how bash arrays work by doing some Google searches, but here are just 2 links to get you started that have some examples and explanations on how they work.
http://www.thegeekstuff.com/2010/06/bash-array-tutorial/
http://www.tldp.org/LDP/abs/html/arrays.html
As for outputting the results in tab separated formatted, yeah, that can be done. The only thing I'm not sure about is how well they will get preserved when you run a JSS report. I haven't actually tried that to my knowledge. I'm not sure if the JSS ends up stripping them out or doesn't respect those characters in the actual csv file.
But as an example, if you change the resulttmp line in the script from:
resulttmp+=("${file}:
Creation Date: $CDate
File Size: $FSize KB")
to
resulttmp+=("${file} $CDate $FSize")
This will create the array with values added to each line separated by tabs (you can't actually see them here, but the white space between each variable is a tab. Just be sure to copy/paste it from the example above and it should be maintained.)
If you'd like to experiment with how it outputs, change the final echo line to something like this instead, and run the script on a Mac you know has some of the .nsf file on it.
echo "$(printf '%s
' "${resulttmp[@]}")" > ~/Desktop/foundfiles.tsv
This will output a file to the current user's Desktop called "foundfiles.tsv" You can open that in Excel and tell it to use tab as the delimiter when it opens it. You'll see that any files found will show up with the respective creation date and file size in their own columns.
Your last question is much more involved than just locating files and getting them into an EA. I don't know how much I can help with that. I'm sure its possible to copy any files up to a share, but I don't have any examples of that I can give you since we don't do these kinds of things. You may want to do some searches here on JN to see if someone has posted a working example of a script that can do what you're looking for to start with.
Posted on 07-09-2015 08:34 AM
Again thanks so much this will help me a lot. I will be glad when we are done With Lotus Notes. ...
I will look at the info / links you supplied and play around with the sample scripts to see the different results. This was very helpful and enlightening for me.
Thanks