Quick little script to read the length of a string: #!/bin/bash echo "Enter some text"read mytextlength=${#mytext}echo $length
-
-
Brace Yourself!
Brace yourself, ’cause I’m a tool (or don’t brace yourself if you’ve read much of my writing or met me since you already knew this to be the case). Classic cedge-fail moment that I just had to share. What do you do when you have a variable before a string of text but cannot have any spaces? You brace your variable. Basically, place the $ followed by the variable that is wrapped in the braces. For example, if I was going to put cedge as the content of a variable and then write a file called cedge.plist from the contents then I would use the following. user=cedge touch “${user}.plist” Big…
-
Don't Defrag the Whole SAN
I see a numer of environments that are running routine defragmentation scripts on Xsan volumes. I do not agree with this practice, but given certain edge cases I have watched it happen. When defragmenting a volume, there is no reason to do so to the entire volume. Especially if much of the content is static and not changing very often. And if specific files doesn’t have a lot of extents then they are easily skipped. Let’s look at a couple of quick ways to narrow down your defrag using snfsdefrag. The first is by specifying the path. In this case you would specify a -r option and follow that with…
-
Pushing Additions to CoRD from Shell
Since I already started down this path, we can also push out information for a Windows box therefore programatically allowing you to push updates to two programs and be able to manage all your boxen. You would push something along the following (creating a file that matches your naming convention followed by .rdp): connect to console:i:0 bitmapcachepersistenable:i:1 redirectdrives:i:0 disable wallpaper:i:1 disable full window drag:i:1 disable menu anims:i:1 disable themes:i:0 audiomode:i:0 desktopwidth:i:1024 desktopheight:i:768 session bpp:i:16 cord save password:i:0 startdisplay:i:0 cord fullscreen:i:0 cord row index:i:2 full address:s:10.10.10.10 username:s:charles domain:s: cord label:s:charles So programatically you can change any of the settings by replacing it with a variable. Therefore, in a script if we…
-
Randomizing the Mac OS X Software Update Server
I’ve had a few instances where there was no way to setup round robin DNS or a load balancer and we were looking to alternate between a bunch of software update servers. In order to do so, I’ve written a quick shell script to do so. Here it is, in pieces, so it makes sense. The following is a quick script to pull a URL from a random list of servers: #!/bin/bash Sus=”http://swupd.krypted.com:8088 http://sus.krypted.com:8088 http://sus1.krypted.com:8088 http://sus2.krypted.com:8088 http://sus3.krypted.com:8088 http://sus4.krypted.com:8088 http://sus5.krypted.com:8088 http://sus6.krypted.com:8088 http://sus7.krypted.com:8088 http://sus8.krypted.com:8088 http://sus9.krypted.com:8088 http://sus10.krypted.com:8088″ sus=($Sus) num_sus=${#sus[*]} echo -n ${sus[$((RANDOM%num_sus))]} exit 0 This script would simply write to the screen one of the software update servers that we’ve loaded up into…
-
AppleScript Studio
It’s not just a great acronym. If you want to put GUI wrappers around shell scripts it’s probably the easiest thing to use…
-
Positional Parameters and Packaging
When packaging it is worth note that Apple reserves some positional paremeters for your scripts. These are defined at http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/SoftwareDistribution/Install_Operations/Install_Operations.html#//apple_ref/doc/uid/10000145i-CH14-SW1 They include: $1: Path to the package $2: Path to the destination. $3: Installation volume. $4: Root directory