Skip to main content
Solved

Populate an EA from a string of text from a file


Forum|alt.badge.img+10

Greetings,
I'm trying to populate an EA by reading a string of text from the hidden .identity file (located in /Library/Application Support/CrashPlan) that is created when CrashPlan is installed and configured for a user. From what I can see, the user account that is configured is in the last line of the file. I need to get some of that string in an EA. The string looks something like this: "username=johnsmith@domain.edu". I only need the "johnsmith" part of the text. I believe this can be done using the cat, grep, or sed command(s) but I am not sure where to start. Any help would be much appreciated.

Best answer by Jerneheim

Hi Joe,
This might be a start.

VAR=$(cat /Library/Application Support/CrashPlan/.Identity |grep username= |sed -e 's/.*=(.*)@.*/1/'); echo "<result>$VAR</result>"
View original
Did this topic help you find an answer to your question?

5 replies

Forum|alt.badge.img+13
  • Contributor
  • 18 replies
  • Answer
  • July 3, 2020

Hi Joe,
This might be a start.

VAR=$(cat /Library/Application Support/CrashPlan/.Identity |grep username= |sed -e 's/.*=(.*)@.*/1/'); echo "<result>$VAR</result>"

Forum|alt.badge.img+12
  • Valued Contributor
  • 359 replies
  • July 3, 2020

Friends of awk would probably say

#!/bin/sh
VAR=$(awk -F'[=@]' '/username/ {print $2}' bla.txt );echo "<result>$VAR</result>"

Forum|alt.badge.img+10
  • Author
  • Valued Contributor
  • 108 replies
  • July 6, 2020

@Jerneheim and @mschroder, Thank you both for your responses. If CrashPlan isn't installed on a machine, it just keeps the EA blank. Do you know what I could add to the script so instead of it coming up blank, it would read "Not Installed"?


Forum|alt.badge.img+19
  • Honored Contributor
  • 582 replies
  • July 6, 2020

@joethedsa , just add an if statement to check the value returned. From either option, remove the ;echo "<result>$VAR</result>" and add these lines:

if [ -z "$VAR" ]; then
    echo "<result>Not Installed</result>"
else
    echo "<result>$VAR</result>"
fi

Forum|alt.badge.img+10
  • Author
  • Valued Contributor
  • 108 replies
  • July 6, 2020

@RBlount, thanks for chiming in. That did the trick!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings