BASH- Need help pulling data from .emlx


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH- Need help pulling data from .emlx
# 1  
Old 11-20-2013
Apple BASH- Need help pulling data from .emlx

Hello, fellow computer junkies. First time poster! My boss wrote an application (Mavericks 10.9, Mountain Lion 10.8) that checks a user's security settings. The user runs the application, then it spits out an email that is sent back to our inbox showing the results. On our end, we have a mail rule setup which sorts all of those results messages into a local mailbox. The email body looks something like this:

Operating System- 10.9
HDD Used- 79%
Filevault Enabled- PASS
Firewall Enabled- FAIL
VPN split tunneling disabled- PASS

I am writing a script that will help me manage these emails. The goal is to run the script and have it spit out who has passed and who has failed into a simple spreadsheet. The identifiers can be the PASS or FAIL status in the message. Basically, if it says FAIL in the message I want it sorted to the "Fail" Column on the spreadsheet. If it does not contain FAIL, it can sort to the Pass column of the spreadsheet

I've STARTED with the code below but it does't work on files that have spaces in the name. It does, however, work on files with no spaces in the name. My train of thought is sort the messages between pass and fail, then output the email address to a spreadsheet appropriately. Anyways, any help is greatly appreciated! Assume I am a N00B Smilie
Code:
find pathname -type f | zargs grep -li fail

# 2  
Old 11-20-2013
You could try this:

Code:
find pathname -type f | while read filename
do
    if grep -qi fail "$filename"
    then
         printf "$filename\tFAIL\t\n"
    else
         printf "$filename\t\tOK\n"
    fi
done > outfile.txt

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 11-20-2013
This helps me with my first step, thank you. Can you explain the characters used?
Code:
 "$filename\tFAIL\t\n"
         "$filename\t\tOK\n"

I'm trying to make sense of the "t" and "OK" used. I understand the rest.
# 4  
Old 11-20-2013
\t is a TAB character \n is a New Line, so we are creating a file for import into a sheet with 3 TAB separated columns filename,fail and pass. Probably should have used PASS instead of OK as this is what you mentioned in your first post.
This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 11-20-2013
Got it, so I should change the OK to PASS. I appreciate the explanation, now lets see if I can finish this off.
# 6  
Old 11-20-2013
small improvements. not that it's likely you'll have % in your filenames, but you should use printf properly: printf '%s\tFAIL\t\n' "$filename"

if using bash you'd also want read -r to disable backslash processing too.

examples:
Code:
mute@thedoctor:~$ read var <<< 'file\name'; echo "$var"
filename
mute@thedoctor:~$ read -r var <<< 'file\name'; echo "$var"
file\name
mute@thedoctor:~$ filename='%strange'; printf "$filename\tOK\n"
trange  OK

These 2 Users Gave Thanks to neutronscott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash: Pulling first and last character in string

I am writing a bash script that will find all references to the “Well_List” in the “Comp_File”. I am filtering a Well_List that contains the following: TEST_WELL_01 TEST_WELL_02 TEST_WELL_11 TEST_WELL_22 GOV_WELL_1 GOV_WELL_201 PUB_WELL_57 PUB_WELL_82 . . Comparison... (5 Replies)
Discussion started by: petfyp
5 Replies

2. Shell Programming and Scripting

Pulling information from a data file by date

awk -v now="$(date +%s)" -v tDiff="${USERMINUTES}" ' BEGIN { FS="=" if (!now) now=systime() if (!tDiff) tDiff=60*60 p=1 } /{/ {rec=$0;p=1;next} /}/ && rec && p {print rec ORS $0;next} $1=="entry_time" { if (now-$2>tDiff)p=0 } {rec=rec ORS $0}'... (6 Replies)
Discussion started by: SkySmart
6 Replies

3. Shell Programming and Scripting

Pulling Data, Then Moving to the Next File

I'm scanning a list of emails- I need to pull 2 pieces of data, then move to the next file: Sender's Email Address Email Date I need these to be outputted into a single column- separated by a ",". Like this: Email1's Address, Email1's Date Stamp Email2's Address, Email2's Date Stamp... (4 Replies)
Discussion started by: sudo
4 Replies

4. Shell Programming and Scripting

Pulling data from xml

Hi there, Please could anyone help with this. I have an xml file that contains repeating values eg <Rule name> AAAAA <Action> BBBBB </Action> <Data> CCCCC </Data> <Type> DDDDD </Type> </Rule name> <Rule name> A1A1A1A1 <Action> B1B1B1B1 </Action> <Data> C1C1C1C </Data> <Type>... (4 Replies)
Discussion started by: ssideel
4 Replies

5. Shell Programming and Scripting

Basic bash -- pulling files from an FTP server

Hi guys. Very new to this so apologies if this is ridiculously obvious, but I am not sure why this isn't working. I want to pull a file off an FTP server. I currently do it through windows, which is no problem, but I want to move everything to a Linux box I just installed. wget won't work as the... (4 Replies)
Discussion started by: majormajormajor
4 Replies

6. Shell Programming and Scripting

Help with pulling / filtering data from a .csv

Good day Gurus, I have a csv file that contains an inventory of active servers. This csv file contains a well over a hundred systems (IBM, SUN, HP). It also contains those systems details. See below for an example hostA,invver,1.02,20100430 hostA,date,08/30/2010,06:18 hostA,use,"Unknown... (4 Replies)
Discussion started by: LuffyDMonkey
4 Replies

7. Shell Programming and Scripting

Bash script pulling variable from query_string

I have a variable embedded in a long string called "commands" coming in on a query_string. I need to copy the string to a file with the variable $loop1 converted before it writes. Right now, it writes the varible itself instead of what it should be. QUERY_STRING... (2 Replies)
Discussion started by: numele
2 Replies

8. Shell Programming and Scripting

SFTP to server, pulling data and removing the data

Hi all, I have the following script, but are not too sure about the syntax to complete the script. In essence, the script must connect to a SFTP server at a client site with username and password located in a file on my server. Then change to the appropriate directory. Pull the data to the... (1 Reply)
Discussion started by: codenjanod
1 Replies

9. Shell Programming and Scripting

Pulling data and following lines from file

I saw a few posts close to what i want to do, but they didn't look like they would work exactly.. or I need to think out of the box on this. I have a file that I keep server stats in for my own performance analysis. this file has the output from many commands in it (uptime, vmstats, ps, swap... (2 Replies)
Discussion started by: MizzGail
2 Replies
Login or Register to Ask a Question