2

My work needs to clone some Thin Clients and they use Ubuntu as base to the VMware Client, but the problem is we have to edit manually the line in the /etc/vmware/view-mandatory-config with the MAC of the Hardware.

view.sslVerificationMode = "3"
view.defaultUser = "CM-d4_85_64_71_58_44"
view.autoConnectDesktop = "TRUE"
view.autoConnectBroker = "TRUE"
view.kioskLogin = "TRUE"
view.nonInteractive = "TRUE"
view.fullScreen = "TRUE"
view.nomenubar = "TRUE"
view.defaultBroker = "viewcs"

We need to create a script that run automatically at boot (1 time and delete it self) and get the MAC of eth0 and past it like in the config file above.

view.defaultUser = "CM-d4_85_64_71_58_44"

We need this so we can save a lot of time.

---EDIT--- With what was answered I did the following script, still incomplete but Is working.

MAC=$(ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')
echo "
view.sslVerificationMode = *3*
view.autoConnectDesktop = *TRUE*
view.autoConnectBroker = *TRUE*
view.kioskLogin = *TRUE*
view.nonInteractive = *TRUE*
view.fullScreen = *TRUE*
view.nomenubar = *TRUE*
view.defaultBroker = *viewcs*
view.defaultUser = *CM-${MAC//:/_}*
" > /etc/vmware/view-mandatory-config;
sed -i 's/*/"/g' /etc/vmware/view-mandatory-config

Is incomplete because, I don't know how to print (") in the file so I've used * and after I used "sed" to change * to ("), it's working like a charm.

I don't know why but I was not able to make this script run in boot.

First, I set it into /etc/rc.local and it did not ran. Second, I tried to put it in crontab as @reboot /etc/vmware/MAC.sh, and it not worked.

Thanks for your help.

  • 2
    ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' will get MAC address. (From stackoverflow.com/questions/245916/…) I am not good at shell scripting, still learning, but maybe someone can help bring this into text file – No Time Apr 29 '14 at 21:34
2

This should give you the string you want.

MAC=$(ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'); echo "CM-${MAC//:/_}";

Replace eth0 with whatever the interface is. Output:

CM-d4_85_64_71_58_44

The grep code came from here:

https://stackoverflow.com/questions/245916/best-way-to-extract-mac-address-from-ifconfig-output

  • When I ran the script I got a error: ./MAC.sh: 2: ./MAC.sh: Bad substitution, if I use a the following part direct on terminal I got the mac in my screen. $(ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}') – André M. Faria Apr 30 '14 at 1:06
  • 1
    Can you post how you put it in the MAC.sh script? – Nattgew Apr 30 '14 at 14:57
  • 1
    I started it with #!/bin/sh, but I read in another question that I have to use #!/bin/bash, and it worked, I will edit my top post with more information. – André M. Faria May 3 '14 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.