Skip to main content
Question

Change username & computer name from script

  • November 24, 2010
  • 2 replies
  • 0 views

Hello,

I have a script that I run every login to change the computer name in JSS & locally :

#!/bin/sh

APIUSER=sdf
APIPASS=sdf
JSS=cs.esl-lan.net

#Get Last User

LASTUSER=/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'

#Get MAC Address

MACADDRESS=system_profiler SPNetworkDataType | grep "MAC Address:" | awk '{print $3}' | sed s/:/./g | head -1

#Change computer name in JSS to last user logged in
echo curl -k -u $APIUSER:$APIPASS http://$JSS:8443/JSSResource/computers/macaddress/$MACADDRESS -d "name=$LASTUSER" -X PUT
/usr/bin/curl -k -u $APIUSER:$APIPASS http://$JSS:8443/JSSResource/computers/macaddress/$MACADDRESS -d "name=$LASTUSER" -X PUT

#Change local computer name
echo /usr/sbin/jamf setComputerName -name $LASTUSER

/usr/sbin/jamf setComputerName -name $LASTUSER

So far it work, but I would like to update the username of the JSS computer entry, which is located in <computer><location><username/></location></computer>

I'm sure it's possible as it's in the python example, but I can't figure how to do it with curl. I get a 200. Here's the command :

curl -k -v -u sdf:sdf http://cs.esl-lan.net:9006/JSSResource/computers/macaddress/00.26.08.0e.a8.54/subset/location -d "username=esl-francois" -X PUT

To be honest, I'm not confident at all with REST, I've tried to read some documentation, but I don't really understand why it's failing.

Francois

--

Francois Tiffreau | IT operations Manager

ESL Education
Head office – Switzerland
Grand-Rue 50, 1820 Montreux
t +41 21 962 88 80 | f +41 21 962 88 81
skype esl.francois

http://www.esl-education.org

Please consider the environment before printing this e-mail

This e-mail message may contain certain confidential and privileged material for the sole use of the intended recipient. Any review, use or distribution by others is prohibited. If you are not the intended recipient, please contact the sender and destroy or delete all copies.

![external image link](attachments/126ec39eec6c46fa855abecd546d8c53)

2 replies

Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • November 24, 2010

So, you are reading this over HTTP to your JSS?

If you want to update the computer name and the local user name in the
JSS computer record you can do this with recon.


  • 0 replies
  • November 25, 2010
On 24 nov. 2010, at 22:48, Thomas Larkin wrote: So, you are reading this over HTTP to your JSS? If you want to update the computer name and the local user name in the JSS computer record you can do this with recon.

Yes, but it takes much longer as it has to run a full inventory.

Question 2 : if I use recon and fill the username field, is it possible to ask the JSS to do an LDAP lookup on it, like in inventory doing Edit > Location > Check name ?

Thanks

Franocis

>>> ESL - Francois TIFFREAU 11/24/10 5:42 AM >>> Hello, I have a script that I run every login to change the computer name in JSS & locally : ============================================================== #!/bin/sh APIUSER=sdf APIPASS=sdf JSS=cs.esl-lan.net #Get Last User LASTUSER=/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }' #Get MAC Address MACADDRESS=system_profiler SPNetworkDataType | grep "MAC Address:" | awk '{print $3}' | sed s/:/./g | head -1 #Change computer name in JSS to last user logged in echo curl -k -u $APIUSER:$APIPASS http://$JSS:8443/JSSResource/computers/macaddress/$MACADDRESS -d "name=$LASTUSER" -X PUT /usr/bin/curl -k -u $APIUSER:$APIPASS http://$JSS:8443/JSSResource/computers/macaddress/$MACADDRESS -d "name=$LASTUSER" -X PUT #Change local computer name echo /usr/sbin/jamf setComputerName -name $LASTUSER /usr/sbin/jamf setComputerName -name $LASTUSER ============================================================== So far it work, but I would like to update the username of the JSS computer entry, which is located in <computer><location><username/></location></computer> I'm sure it's possible as it's in the python example, but I can't figure how to do it with curl. I get a 200. Here's the command : curl -k -v -u sdf:sdf http://cs.esl-lan.net:9006/JSSResource/computers/macaddress/00.26.08.0e.a8.54/subset/location -d "username=esl-francois" -X PUT To be honest, I'm not confident at all with REST, I've tried to read some documentation, but I don't really understand why it's failing. Francois -- Francois Tiffreau | IT operations Manager ESL Education Head office – Switzerland Grand-Rue 50, 1820 Montreux t +41 21 962 88 80 | f +41 21 962 88 81 skype esl.francois http://www.esl-education.org Please consider the environment before printing this e-mail This e-mail message may contain certain confidential and privileged material for the sole use of the intended recipient. Any review, use or distribution by others is prohibited. If you are not the intended recipient, please contact the sender and destroy or delete all copies. This message has been sent from the Kansas City, Kansas Public Schools. The information contained in this email and any attachments may be privileged and confidential, and are intended only for the individual or entity identified as the addressee. If you are not the addressee, or if the message has been addressed to you in error, you are not authorized to read, retain, copy, or distribute the message or any attachments. If you have received the message in error, please delete it and any attachments and notify the sender by return e-mail or by telephone. Thank you.

--

Francois Tiffreau | IT operations Manager

ESL Education
Head office – Switzerland
Grand-Rue 50, 1820 Montreux
t +41 21 962 88 80 | f +41 21 962 88 81
skype esl.francois

http://www.esl-education.org

Please consider the environment before printing this e-mail

This e-mail message may contain certain confidential and privileged material for the sole use of the intended recipient. Any review, use or distribution by others is prohibited. If you are not the intended recipient, please contact the sender and destroy or delete all copies.

![external image link](attachments/a70e41c5cb074c73872cdf39410fd1d9)
![external image link](attachments/f3a1580a7b624ee990dd82f275879eea)


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