<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-35522698</id><updated>2011-07-28T21:43:34.208-08:00</updated><category term='xml'/><category term='array to xml'/><category term='MySQL'/><category term='array2xml'/><category term='php'/><category term='php array'/><category term='mac os x'/><category term='php xml'/><category term='scutil'/><category term='xhtml'/><category term='LocalHostName'/><category term='php array to xml'/><category term='ComputeName'/><category term='array'/><category term='php array2xml'/><title type='text'>Mark Carver - Code Repository</title><subtitle type='html'>I've noticed that many times people will develop code that either doesn't make sense, is messy or is simply not viable. You can rest assured that this site will always provide the cleanest and most concise approach to coding. That being said, I am still only human and from time to time, there might be an error or two. However, if you catch it, let me know ASAP! I will aways include version numbers with my code so that you might know if you have the most current one. Enjoy!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://oldgreenhorn.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35522698/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://oldgreenhorn.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Mark Carver</name><uri>http://www.blogger.com/profile/02042112214635040477</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_NmJq0nutYPY/Sjih1gjTDRI/AAAAAAAAABU/ly0VfBpCVtM/S220/P5280130.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-35522698.post-5410572613508008073</id><published>2009-06-17T11:03:00.009-08:00</published><updated>2009-06-17T11:51:07.999-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='scutil'/><category scheme='http://www.blogger.com/atom/ns#' term='LocalHostName'/><category scheme='http://www.blogger.com/atom/ns#' term='mac os x'/><category scheme='http://www.blogger.com/atom/ns#' term='ComputeName'/><title type='text'>Mac OS X - Advanced Computer(Re)Name via MySQL (Extended)</title><content type='html'>No comments (condensed) version:&lt;br /&gt;&lt;a href="http://codesnippets.joyent.com/posts/show/2155" target="_blank"&gt;http://codesnippets.joyent.com/posts/show/2155&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:8pt"&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;# Script:   mysql_computername.sh&lt;br /&gt;# Version:   1.0&lt;br /&gt;# Description:  Rename computers dynamically on system startup.&lt;br /&gt;#     Variables are pulled from a MySQL database for&lt;br /&gt;#     easier management.&lt;br /&gt;#&lt;br /&gt;# Developed by:  Mark Carver © 2009&lt;br /&gt;# Email:   mark_carver@jsd.k12.ak.us&lt;br /&gt;# Website:   http://oldgreenhorn.blogspot.com&lt;br /&gt;&lt;br /&gt;export PATH=${PATH}:/usr/local/mysql/bin&lt;br /&gt;&lt;br /&gt;# MySQL Configuration&lt;br /&gt;mysql_host='localhost'    # Domain, IP&lt;br /&gt;mysql_user='ReadOnlyUser'    # Preferably use a user that only has read only access as the password&lt;br /&gt;mysql_password='YoUrPaSsWoRd'  # is visible in this script.&lt;br /&gt;mysql_db='database_name'&lt;br /&gt;mysql_connection="mysql -s -N -w --connect_timeout=5 -h ${mysql_host} -u ${mysql_user} --password=${mysql_password} ${mysql_db}"&lt;br /&gt;&lt;br /&gt;# Test for connection to host. Computer needs to start network connections on startup, otherwise this script would often fail.&lt;br /&gt;# Time is calculated in minutes by multiplying the sleep (number of seconds it waits before trying again) and while loops &lt;br /&gt;# (number of loops it will complete before failing) then dividing by 60 (seconds).&lt;br /&gt;# 10 seconds x 30 loops = 300 seconds / 60 seconds = 5 minutes&lt;br /&gt;i=0&lt;br /&gt;while [ $i -lt 30 ]&lt;br /&gt;do&lt;br /&gt;    if eval "ping -c 1 -q ${mysql_host}"; then&lt;br /&gt;  internet='connected'&lt;br /&gt;        break&lt;br /&gt;    else&lt;br /&gt;      sleep 10&lt;br /&gt;  let i+=1&lt;br /&gt;    fi&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;if [ "${internet}" == 'connected' ]; then&lt;br /&gt; &lt;br /&gt; # Test for connection to MySQL database. Read above for instructions on changing timout settings.&lt;br /&gt; m=0&lt;br /&gt; while [ $m -lt 30 ]&lt;br /&gt; do&lt;br /&gt;  if eval "${mysql_connection} -e \"SHOW DATABASES\""; then&lt;br /&gt;   mysql_status='connected'&lt;br /&gt;   break&lt;br /&gt;  else&lt;br /&gt;   sleep 10&lt;br /&gt;   let m+=1&lt;br /&gt;  fi&lt;br /&gt; done&lt;br /&gt;&lt;br /&gt; if [ "${mysql_status}" == 'connected' ]; then&lt;br /&gt;&lt;br /&gt;  # Pull variables from the MySQL server&lt;br /&gt;&lt;br /&gt;  # ${template}: Naming scheme that allows you to dynamically change how the computer name is displayed.&lt;br /&gt;  #     When storing the value in the MySQL database, you must use single quotes ( ' ) around&lt;br /&gt;  #     any metacharacters ( |  &amp; ; ( ) &lt; &gt; space tab) that is used in your naming scheme.&lt;br /&gt;  #    Not doing so will break the script. -------------------See below for more details.&lt;br /&gt;  template=`${mysql_connection} -e "SELECT value FROM settings WHERE attribute='template'"`&lt;br /&gt;&lt;br /&gt;  # ${mac}:  Pulls the MAC address of this computer and searches for it on the MySQL database.&lt;br /&gt;  #    It then parses out the ":" and changes the case from lower to UPPER. 00:1f:f3:d0:a5:60 &gt; 001FF3D0A560&lt;br /&gt;  #    You may need to modify this line to suit how you MAC addresses are stored in your database.&lt;br /&gt;  #    To keep the colons (:) in, remove the following: | tr -d ':'&lt;br /&gt;  #    To keep the case lower, remove the following:  | tr 'a-z' 'A-Z'&lt;br /&gt;  mac=`ifconfig en0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' | tr -d ':' | tr 'a-z' 'A-Z'`&lt;br /&gt;  # DEBUG:  Uncomment the line below and replace the MAC address with one that is currently in your&lt;br /&gt;  #    MySQL database. This will allow you to run this script locally to smooth out any settings.&lt;br /&gt;  #    Make sure you comment it back or remove the line before you deploy, otherwise you'll get a&lt;br /&gt;  #    nasty surpise ;)&lt;br /&gt;  mac="001FF3D0A560"&lt;br /&gt;  &lt;br /&gt;  # ${exists}: Checks the MySQL database for a record that matches the MAC address  &lt;br /&gt;  exists=`${mysql_connection} -e "SELECT ethernet FROM computers WHERE ethernet='${mac}'"`&lt;br /&gt;  &lt;br /&gt;  if [ "${exists}" != '' ]; then&lt;br /&gt;  &lt;br /&gt;   ###############################################  Custom Variables ###############################################&lt;br /&gt;   # Here is where you will create your own variables depending on what you wish to display for the computer name. #&lt;br /&gt;&lt;br /&gt;   fas=`${mysql_connection} -e "SELECT fas FROM computers WHERE ethernet='${mac}'"`&lt;br /&gt;   last_name=`${mysql_connection} -e "SELECT last_name FROM users WHERE fas='${fas}'"`&lt;br /&gt;   first_name=`${mysql_connection} -e "SELECT first_name FROM users WHERE fas='${fas}'"`&lt;br /&gt;   school=`${mysql_connection} -e "SELECT school FROM computers WHERE fas='${fas}'"`&lt;br /&gt;   team=`${mysql_connection} -e "SELECT team FROM users WHERE fas='${fas}'"`&lt;br /&gt;   cart=`${mysql_connection} -e "SELECT cart FROM computers WHERE fas='${fas}'"`&lt;br /&gt;   slot=`${mysql_connection} -e "SELECT slot FROM computers WHERE fas='${fas}'"`&lt;br /&gt;   if [ "${cart}" != "" ] &amp;&amp; [ "${slot}" != "" ]&lt;br /&gt;   then&lt;br /&gt;    fas="${cart}${slot}-${fas}"&lt;br /&gt;   fi&lt;br /&gt; &lt;br /&gt;   if [ "${last_name}" != "" ] || [ "${first_name}" != "" ]; then&lt;br /&gt;    lastname_first="- ${last_name}, ${first_name}"&lt;br /&gt;   else&lt;br /&gt;    lastname_first=""&lt;br /&gt;   fi&lt;br /&gt;   &lt;br /&gt;   #                            #&lt;br /&gt;   ############################################## End Custom Variables #############################################&lt;br /&gt; &lt;br /&gt;   # Takes your MySQL template string and evaluates it to include the variables. Example of the value that's stored:&lt;br /&gt;   #         ${school} ${team} ${lastname_first} '('${fas}')'&lt;br /&gt;   # Any metacharacters will need to be put in single quotation. You must also put the EXACT variable for this to work.&lt;br /&gt;   # Otherwise it will just spit out garbage.&lt;br /&gt;   computer_name=`eval echo ${template}`&lt;br /&gt; &lt;br /&gt;   # Takes the compiled computer name and condenses any extra spaces for variables that may have been blank.&lt;br /&gt;   # Then formats the computer name to an appropriate LocalHostName with lower case, no metacharacters, and only one hyphen :) &lt;br /&gt;   computer_name=`echo ${computer_name} | tr -s " "`&lt;br /&gt;   local_hostname=`echo ${computer_name} | tr -s "[:punct:]" "-" | tr -c -s '\12\60-\172' "-" | tr 'A-Z' 'a-z' | sed 's/-$//'`&lt;br /&gt;&lt;br /&gt;   # And finally, we can safely set the computer name and local host name!&lt;br /&gt;      scutil --set ComputerName "${computer_name}"&lt;br /&gt;   scutil --set LocalHostName "${local_hostname}"&lt;br /&gt;   exit 0  &lt;br /&gt;  else&lt;br /&gt;   logger -s "The MAC address: ${mac} does not exist in the database. Will try again next startup/login."&lt;br /&gt;   exit 0&lt;br /&gt;  fi&lt;br /&gt; else&lt;br /&gt;  logger -s "MySQL connection timeout reached. Failed connecting to MySQL database: ${mysql_db} at ${mysql_host}. Will try again next startup/login."&lt;br /&gt; fi&lt;br /&gt;else&lt;br /&gt; logger -s "Host connection timeout reached. Failed connecting to host: ${mysql_host}. Will try again next startup/login."&lt;br /&gt;fi&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35522698-5410572613508008073?l=oldgreenhorn.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oldgreenhorn.blogspot.com/feeds/5410572613508008073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35522698&amp;postID=5410572613508008073' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35522698/posts/default/5410572613508008073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35522698/posts/default/5410572613508008073'/><link rel='alternate' type='text/html' href='http://oldgreenhorn.blogspot.com/2009/06/mac-os-x-advanced-computerrename-via.html' title='Mac OS X - Advanced Computer(Re)Name via MySQL (Extended)'/><author><name>Mark Carver</name><uri>http://www.blogger.com/profile/02042112214635040477</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_NmJq0nutYPY/Sjih1gjTDRI/AAAAAAAAABU/ly0VfBpCVtM/S220/P5280130.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35522698.post-2681190738567030254</id><published>2008-02-21T19:38:00.009-09:00</published><updated>2008-03-09T11:31:13.282-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='xhtml'/><category scheme='http://www.blogger.com/atom/ns#' term='array'/><category scheme='http://www.blogger.com/atom/ns#' term='php array2xml'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='php xml'/><category scheme='http://www.blogger.com/atom/ns#' term='php array to xml'/><category scheme='http://www.blogger.com/atom/ns#' term='array2xml'/><category scheme='http://www.blogger.com/atom/ns#' term='php array'/><category scheme='http://www.blogger.com/atom/ns#' term='array to xml'/><title type='text'>PHP array2xml() -  Coverts An Array To XML Structure</title><content type='html'>&lt;div style="overflow:scroll;"&gt;&lt;pre&gt;&lt;br /&gt;/*&lt;br /&gt; * Function:    array2xml()&lt;br /&gt; *&lt;br /&gt; * Description: Array to XML is a function that does just that... converts any given&lt;br /&gt; *              array to xml structure.&lt;br /&gt; *&lt;br /&gt; * Version:     1.0&lt;br /&gt; *&lt;br /&gt; * Created by:  Marcus Carver © 2008&lt;br /&gt; * Email:       info@marcuscarver.com&lt;br /&gt; * Link:        http://blog.marcuscarver.com/&lt;br /&gt; *&lt;br /&gt; * Arguments :  $array      - The array you wish to convert into a XML structure.&lt;br /&gt; *              $name       - The name you wish to enclose the array in, the 'parent'&lt;br /&gt; *                            tag for XML.&lt;br /&gt; *              $standalone - This will add a document header to identify output&lt;br /&gt; *                            solely as a XML document.&lt;br /&gt; *              $beginning  - INTERNAL USE... DO NOT USE!&lt;br /&gt; *&lt;br /&gt; * Return:      Gives a string output in a XML structure&lt;br /&gt; *&lt;br /&gt; * Use:         echo array2xml($products,'products');&lt;br /&gt; *              die;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;function array2xml($array, $name='array', $standalone=TRUE, $beginning=TRUE) {&lt;br /&gt;&lt;br /&gt;  global $nested;&lt;br /&gt;&lt;br /&gt;  if ($beginning) {&lt;br /&gt;    if ($standalone) header("content-type:text/xml;charset=utf-8");&lt;br /&gt;    $output .= '&lt;'.'?'.'xml version="1.0" encoding="UTF-8"'.'?'.'&gt;' . LF;&lt;br /&gt;    $output .= '&lt;' . $name . '&gt;' . LF;&lt;br /&gt;    $nested = 0;&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  // This is required because XML standards do not allow a tag to start with a number or symbol, you can change this value to whatever you like:&lt;br /&gt;  $ArrayNumberPrefix = 'ARRAY_NUMBER_';&lt;br /&gt;  &lt;br /&gt; foreach ($array as $root=&gt;$child) {&lt;br /&gt;    if (is_array($child)) {&lt;br /&gt;      $output .= str_repeat(" ", (2 * $nested)) . '  &lt;' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '&gt;' . LF;&lt;br /&gt;      $nested++;&lt;br /&gt;      $output .= array2xml($child,NULL,NULL,FALSE);&lt;br /&gt;      $nested--;&lt;br /&gt;      $output .= str_repeat(" ", (2 * $nested)) . '  &lt;/' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '&gt;' . LF;&lt;br /&gt;    }&lt;br /&gt;    else {&lt;br /&gt;      $output .= str_repeat(" ", (2 * $nested)) . '  &lt;' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '&gt;&lt;![CDATA[' . $child . ']]&gt;&lt;/' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '&gt;' . LF;&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  if ($beginning) $output .= '&lt;/' . $name . '&gt;';&lt;br /&gt;  &lt;br /&gt;  return $output;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35522698-2681190738567030254?l=oldgreenhorn.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oldgreenhorn.blogspot.com/feeds/2681190738567030254/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35522698&amp;postID=2681190738567030254' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35522698/posts/default/2681190738567030254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35522698/posts/default/2681190738567030254'/><link rel='alternate' type='text/html' href='http://oldgreenhorn.blogspot.com/2008/02/php-array2xml-function.html' title='PHP array2xml() -  Coverts An Array To XML Structure'/><author><name>Mark Carver</name><uri>http://www.blogger.com/profile/02042112214635040477</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_NmJq0nutYPY/Sjih1gjTDRI/AAAAAAAAABU/ly0VfBpCVtM/S220/P5280130.JPG'/></author><thr:total>0</thr:total></entry></feed>
