Write Hostname into a file during policy execution

tobiaslinder
Contributor II

Hi
We have problems deploying a network profile because of a defect in the way Casper Suite handles Wired 802.1x Network Profiles.

Now we would like to copy and install the profile on the machines with a Policy. The steps are

  1. Install the profile in /tmp
  2. Run a command that replaces a placeholder with the correct hostname of the machine in the profile needed for the connection
  3. Install the profile

I tried this command:

#!/bin/sh

hostname="$2"

sed -i.backup -e 's/hostname-to-be-replaced/$hostname/' /private/tmp/Wired and Wireless.mobileconfig
# /usr/bin/profiles -I -F /tmp/Wired and Wireless.mobileconfig

But somehow the $2 Variable for the hostname is not recognized. It just writes "$hostname" into the file where the placeholder "hostname-to-be-replaced" was. Any Idea how the correct syntax should be here?

Thanks for your help!

1 REPLY 1

tobiaslinder
Contributor II

Just figured it out by myself :-). Like this ist works

hostname="$2"

sed -i.backup -e "s/hostname-to-be-replaced/$hostname/" /private/tmp/Wired and Wireless.mobileconfig
# /usr/bin/profiles -I -F /tmp/UEFA Wired and Wireless.mobileconfig