Skip to main content
Solved

Crashplan scripting question


Forum|alt.badge.img+6

Hi all,

Hoping someone can help me here. We're going to be deploying crashplan ProE out to our org soon.

In the installer script on the local machine there is a variable for %CP_USERNAME% (or similar) which needs to be the individuals email address.

Is there anyway to pipe the casper $EMAIL variable into the Crashplan username variable?

We do not have AD/LDAP to perform this function unfortunately.

Once again, thank you all in advance.

Best answer by dwandro92

Yes, this could be done using one of the following methods:

1#!/bin/bash
2
3###########################################################################################################
4################## IMPORTANT - ENTER JSS INFORMATION IN "apiQuery" FUNCTION BEFORE USING ##################
5###########################################################################################################
6
7# Set field seperator to newline
8IFS=$'
9'
10
11# Function for querying the JSS API
12# Parameters:
13# (1) URL Suffix for the page that needs to be queried.
14# (2) Value that you are searching for within the JSS API.
15apiQuery() {
16 # Set full URL path to JSS hostname. Example:
17 # jssURL="https://mycompany.mydomain.com:8443"
18 jssURL=""
19
20 # Set JSS API username. Example:
21 # jssUser="CasperAPI"
22 jssUser=""
23
24 # Set JSS API password. Example:
25 # jssPW="password"
26 jssPW=""
27
28 # If requesting JSON response
29 if [ "$1" == "json" ]; then
30 # Get data from JSS and return the JSON response. Add the "-k" switch to the "curl" command if SSL Cert is not trusted.
31 curl "$jssURL/JSSResource/$2" -H 'Accept: application/json' --user "$jssUser:$jssPW" --silent | python -m json.tool
32 # If not requesting the JSON response
33 else
34 # Get data from JSS and return the XML response. Add the "-k" switch to the "curl" command if SSL Cert is not trusted.
35 curl -k "$jssURL/JSSResource/$1" --user "$jssUser:$jssPW" --silent | awk -F "<$2>|</$2>" '{ print $2 }'
36 fi
37}
38
39###########################################################################################################
40############################ OPTION 1 - GET EMAIL ADDRESS FROM COMPUTER RECORD ############################
41###########################################################################################################
42
43# Get hardware UUID/UDID of system
44hwUDID=`system_profiler SPHardwareDataType | awk '/Hardware UUID/{ print $3 }'`
45
46# Get assigned user's email address from the JSS computer record
47assignedUserEmail=`apiQuery "computers/udid/$hwUDID/subset/location" email_address`
48
49###########################################################################################################
50############################## OPTION 2 - GET EMAIL ADDRESS FROM USER RECORD ##############################
51###########################################################################################################
52
53# Get currently logged in user
54targetUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
55");'`
56
57# Get currently logged in user's email address from the JSS user record
58currentUserEmail=`apiQuery "users/name/$targetUser" email`
59
60# Output information
61echo "Assigned User Email Address: $assignedUserEmail"
62echo "Current User Email Address: $currentUserEmail"

I hope this helps!

View original
Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img+9
  • Contributor
  • 125 replies
  • Answer
  • August 28, 2015

Yes, this could be done using one of the following methods:

1#!/bin/bash
2
3###########################################################################################################
4################## IMPORTANT - ENTER JSS INFORMATION IN "apiQuery" FUNCTION BEFORE USING ##################
5###########################################################################################################
6
7# Set field seperator to newline
8IFS=$'
9'
10
11# Function for querying the JSS API
12# Parameters:
13# (1) URL Suffix for the page that needs to be queried.
14# (2) Value that you are searching for within the JSS API.
15apiQuery() {
16 # Set full URL path to JSS hostname. Example:
17 # jssURL="https://mycompany.mydomain.com:8443"
18 jssURL=""
19
20 # Set JSS API username. Example:
21 # jssUser="CasperAPI"
22 jssUser=""
23
24 # Set JSS API password. Example:
25 # jssPW="password"
26 jssPW=""
27
28 # If requesting JSON response
29 if [ "$1" == "json" ]; then
30 # Get data from JSS and return the JSON response. Add the "-k" switch to the "curl" command if SSL Cert is not trusted.
31 curl "$jssURL/JSSResource/$2" -H 'Accept: application/json' --user "$jssUser:$jssPW" --silent | python -m json.tool
32 # If not requesting the JSON response
33 else
34 # Get data from JSS and return the XML response. Add the "-k" switch to the "curl" command if SSL Cert is not trusted.
35 curl -k "$jssURL/JSSResource/$1" --user "$jssUser:$jssPW" --silent | awk -F "<$2>|</$2>" '{ print $2 }'
36 fi
37}
38
39###########################################################################################################
40############################ OPTION 1 - GET EMAIL ADDRESS FROM COMPUTER RECORD ############################
41###########################################################################################################
42
43# Get hardware UUID/UDID of system
44hwUDID=`system_profiler SPHardwareDataType | awk '/Hardware UUID/{ print $3 }'`
45
46# Get assigned user's email address from the JSS computer record
47assignedUserEmail=`apiQuery "computers/udid/$hwUDID/subset/location" email_address`
48
49###########################################################################################################
50############################## OPTION 2 - GET EMAIL ADDRESS FROM USER RECORD ##############################
51###########################################################################################################
52
53# Get currently logged in user
54targetUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
55");'`
56
57# Get currently logged in user's email address from the JSS user record
58currentUserEmail=`apiQuery "users/name/$targetUser" email`
59
60# Output information
61echo "Assigned User Email Address: $assignedUserEmail"
62echo "Current User Email Address: $currentUserEmail"

I hope this helps!


Forum|alt.badge.img+6
  • Author
  • Contributor
  • 27 replies
  • August 28, 2015

You sir are a star, BUT how do i then get that information into the installer script that lives in the crashplan DMG on the local machine ?


Forum|alt.badge.img+9
  • Contributor
  • 125 replies
  • August 28, 2015

The following white paper might help: Administering CrashPlan PROe with the Casper Suite

Basically, just use the code in the user info script (/Library/Application Support/CrashPlan/.custom/userInfo.sh) and set the "CP_USER_NAME" variable to the result of the command.

I created my installation package manually using Composer, and just put my custom.properties, userInfo.sh, and CrashPlan installer in /Library/Application Support/CrashPlan/.custom. In addition, I have a post-install script that runs the actual installer and removes the .custom directory once complete. The final piece of the puzzle is a custom script that is used in my deployment policies, which checks to ensure that requirements are met (i.e. the logged in user is the person that the machine is assigned to). If all of the requirements are met, it triggers the policy which actually installs the custom package.


Forum|alt.badge.img+6
  • Author
  • Contributor
  • 27 replies
  • August 28, 2015

A massive thank you again, you've been a great help !!


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