Archive for ‘CLI’ Category

One of the things I don’t really like about OSX Leopard is the fact that everytime you take a screen shot of a window (Command-Shift-4 followed by Spacebar), it put’s a — for us bloggers — not so good looking shadow around the capture. Well not anymore, use the following command to disable the effect:defaults write disable-shadow -bool trueOnce you issue the command, either logout and back in or kill the SystemUIServer using this command:killall SystemUIServerIf later on you decide to add it back in, delete the preference by issuing the following command:defaults delete disable-shadowFollowed by Logout/Login or the killall command from above. Below you can see the before and after.Have fun and happy capturing :-).

Some CLI tunes…..

datePosted on 20:52, June 28th, 2008 by Many Ayromlou

Just when you thought your command line life was getting boring, we discover these happy tunes for your cut/paste pleasure. Just select the entire line, copy it, open a terminal window, paste it followed by Enter and marvel at your Mac. Yeah it’s a OSX thing and works best under 10.5, so if you’ve got Vista/XP/Linux, this might be a good enough reason to do the switcheroo :-).say -v Good oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooosay -v Bad oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooosascript -e 'say "Dum dum dum dum dum dum dum he he he ho ho ho fa lah lah lah lah lah lah fa lah full hoo hoo hoo" using "Cellos"'osascript -e 'say "Dum dum dee dum dum dum dum dee Dum dum dee dum dum dum dum dee dum dee dum dum dum de dum dum dum dee dum dee dum dum dee dummmmmmmmmmmmmmmmm" using "Pipe Organ"'osascript -e 'say "oh This is a silly song silly song silly song this is the silliest song ive ever ever heard So why keep you listening listening listening while you are supposed to work to work to work to work its because i hate my job hate my job hate my job its because i hate my job more than anything else No its because youve no life youve no life youve no life and you better go get one after forwarding this crap" using "cellos"'Who said you can’t have fun on the commandline?

Twitter from Unix/Linux/OSX command line

datePosted on 11:33, June 12th, 2008 by Many Ayromlou

Yep, you can. Here is the recipe:

1) You need to install “curl” for your OS. OSX comes with it by default which is nice. Most unices out there also have it installed or have it available for download (Ubuntu, Debian users can use “sudo apt-get install curl” to install).
2) Edit a text file using your favourite editor and add the following line in there:
curl --basic --user "youruserid:yourpassword" --data-ascii "status=`echo $@|tr ' ' '+'`" "" -o /dev/null
3) Make sure you replace youruserid and yourpassword with appropriate strings.
4) Save the file as something like and make it executable by issuing this command:
chmod 700 ./
5) Twitter away by using the following command line:
./ "Put your twit in here and press Enter"
6) Done.

Have fun commandline twittering :-).

Turn on/off remote desktop service remotely….

datePosted on 19:21, March 27th, 2008 by Many Ayromlou

Apples remote desktop service is great and it comes in handy, but what happens when you’re 5000 miles away from your desktop, only to find that remote desktop is turned off. Dooohhhh. Well here is a quick tip to turn the damn thing on and off in a second through a remote ssh connection. To turn on the service, ssh to your machine and issue the following commands:$ cd /Library/Preferences
$ echo -n enabled >
And once you’re done, you can turn it off by issuing the following through an ssh session:$ cd /Library/Preferences
$ rm
I’m pretty sure that this only works under Leopard (10.5+), so if you’ve got Tiger you need to look for an alternate way. I don’t have access to a Tiger machine so I can not guarantee that it works or not.

Secure remote backups using Rsync…..

datePosted on 13:36, March 19th, 2008 by Many Ayromlou

While the world was busy trying to figure out how to sync their palm pilots to Windows 98 (or was it 95) Andrew Tridgell was working on his thesis……Rsync. The endall-beall in the world of syncing. You see, if you’ve ever tried any syncing program before you’ll appreciate the ease with which rsync works. You’ll also see the efficiency of it’s algorithm in dealing with changes/updates, and for that you can thank Andrew. I’m just gonna show you how to use this excellent tool along with ssh (another must have/must use free software utility) to setup automated secure backups between two different platforms.

For the purpose of this article I’m using a PowerMac G5 with a 1TB Firewire disk hanging off it as my backup server. As my client I’m using the departmental research server (yes, forget that it’s a server, in this exercise it’s a CLIENT).

So first we need to make sure we have the tools: ssh and rsync. They are already part of my distribution (SuSE Linux 10.1 on the client and OSX 10.5.1 on the server) so I didn’t have to install anything. You want to make sure that your rsync uses protocol version 2.x.x on both sides. (type: rsync –version on your machines to see the protocol version).

Note: You can also grab RsyncX for older OSX versions and/or cwRsync for windows.

Step 1. Is to remove the interactivity that happens during an ssh session (ie: password prompt). To do this we must generate passphraseless keys that we can initially manually exchange between our machines. So in our case we want to grant access to our client machine — via ssh — from the server. Now here is were things get a bit OS specific. Under OSX there is no root account (atleast not one you can log into) by default. In my setup I want to allow (OSX machine) to have access to (Linux machine), so here is what I had to do.

On the OSX machine (server or machine initiating the rsync session) login as the standard user/admin and issue the following commands:
$ sudo su - (you'll be asked for your password and then be in a root careful).
# cd ~ (this is just to make sure we're in root's home directory which is /var/root under OSX).
# ssh-keygen -t dsa -b 1024 (do NOT put in a passphrase when prompted....just press Enter).
Generating public/private dsa key pair.
Enter file in which to save the key (/var/root/.ssh/id_dsa):
Created directory '/var/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/root/.ssh/id_dsa.
Your public key has been saved in /var/root/.ssh/
The key fingerprint is:

Make sure you don’t enter a passphrase when prompted (remember we want a automated operation here). If everything goes right you should have two new files in your .ssh directory named id_dsa (your private key….don’t ever give this to anyone) and (your public key which we are going to use).

Now you need to transfer the key file to your client somehow. I do this just using ssh again. If you want to be totally super secure you can stick it on a usb key and walk it over to your client machine. So still on the server (OSX) machine I do the following (still in roots account, so be careful):
# scp ~/.ssh/
# ssh -l root "chmod 600 ~/.ssh/authorized_keys"

So the first command transfers from the server and copies it to the root’s .ssh directory on the client (and renames it to authorized_keys). The second command issues a remote chmod command to set the right permissions on the authorized_keys file on the client (Linux box).

Now, to verify, while still logged into root on the server (OSX) try to ssh to your client machine (using root’s account on client). If everything works you should be able to log into root’s account on the client (Linux machine) without a password prompt. If you’re prompted for password, stop here, and redo/recheck your procedure.

Step 2. Pheew…..You made it, that was the hard part….the rest is pretty simple. Now we just need to test to make sure things are running smoothly and once that’s done we can automate everything using a cron job (Step 3.). So lets start our test run. For this I’ve chosen to backup the /etc directory on the server (lots of small files, nothing earth shattering) and my chosen path on the server is /Volumes/TERADISK. This is where OSX mounts my firewire drive (your milage may vary). I’ve created a folder on TERADISK called FULLBACKUP, which I use to have rsync house my backups. So to test issue the following command as root (yes still, so be carefull) on the server:
# /usr/bin/rsync -a -v -z -e ssh "" /Volumes/TERADISK/FULLBACKUP/etc
Notice I use /usr/bin to make sure I’m running the kosher version of rsync under OSX Leopard (I have an older rsync in /usr/local/bin that rsyncX installed). Now a word about slashes in rsync. Note that I follow the first /etc with a slash, but not the second occurrence. That’s because I’m telling rsync to grab the files INSIDE /etc on the client (hence the extra / at the end) and sync them to files in /Volumes/TERADISK/FULLBACKUP/etc existing directory on the server (hence the missing / at the end). You can think of a trailing / on a source as meaning “copy the contents of this directory” as opposed to “copy the directory by name”. So hopefully this command worked for you and after a few minutes you have a copy of the /etc directory on the server. If not please stop and review your steps. Do NOT do Step 3. unless Steps 1&2 are verified and working.

Step 3. Well we’ve reached the end. All you have to do now is to use crontab -e command while still logged in as root on the server to add rsync entries for folders you want synced between the client and the server. Note that I do NOT backup absolutely everything off the client, only specific folders (and their subfolders ofcourse). I’m pretty sure that rsync will get confused if you try to sync things like your dev directory from the linux client. In my cron I have the following:
0 4 * * 6 /usr/local/bin/
Which runs the rsync shell script on the server (as root) every saturday at 4:00 am.

That’s it. Hopefully this has been useful…..

Quicktip for Frontrow users (OSX)

datePosted on 13:42, March 15th, 2008 by Many Ayromlou

I bet you didn’t know that Frontrow, Apple’s Media Centre software that ships with every Mac, can actually playback those HD trailers from their site. Well here is a quicktip to enable that functionality:
defaults write EnableHDMovieTrailers TRUE
Once you type this into terminal, start up Frontrow and note that you get a new option under trailers. To disable this functionality issue the following command from a terminal window:
defaults write EnableHDMovieTrailers FALSE

Twitter….the cool way….

datePosted on 18:51, March 7th, 2008 by Many Ayromlou

To be honest, I’ve had a twitter account for a while, but since I need a browser (or phone) to get access to it and twit, I hadn’t used it. But that’s about to change (maybe), since I found out how you can twit from command line. Yep, twit away from any UNIX, Linux, OSX (and Windows) Command prompt. Here is how:

1) First find the program CURL for your intended platform. It comes built into OSX and most Linux distros and there is a port for windows as well (use google).
2) Setup your twitter account.
3) Use this command when you want to twit:
curl -u yourusername:yourpassword -d status="Your Message Here"
Now one thing to remember is that the username and pass get added to your shell history, so if you’re on a public machine (or friends) you might clear the history file (ie: use history -c in bash to clear the command history).

Stream your Linux/Windows/Mac Desktop as video using VLC

datePosted on 17:54, January 8th, 2008 by Many Ayromlou

A buddy of mine (thanks Mike) showed me this today. There is a input Access module in the newer versions of VLC (0.8.6+) called “screen” which makes this possible. To stream your desktop to another machine (ip address: in this case) just use the following command in Linux (sorry command line only):vlc screen:// :screen-fps=30 :screen-caching=100 --sout '#transcode{vcodec=mp4v,vb=4096,acodec=mpga,ab=256,scale=1,width=1280,height=800}:rtp{dst=,port=1234,access=udp,mux=ts}'or in Windows (slightly different syntax) use this command:vlc screen:// :screen-fps=30 :screen-caching=100 :sout=#transcode{vcodec=mp4v,vb=2048,scale=1,acodec=mpga,ab=192,channels=2}:duplicate{dst=std{access=rtp,mux=ts,dst=}}This is one massive command, so lets take a look at it in more detail:

  • screen:// is our input module selection (if you just run vlc screen:// you’ll see your own screen on the server inside vlc….kinda cool)
  • :screen-fps=30 specifies that we want to screengrab at 30 fps (from default 5 fps)
  • :screen-caching=100 sets the internal caching to 100ms (from default 300 ms)
  • –sout is our output chain.
  • #transcode tells vlc that we first want to transcode the input using parameters to follow
  • {} contains our transcoding parameters
  • vcodec=mp4v sets the video codec to mpeg4 video
  • vb=4096 sets the bitrate of the transcoded video (4Mb/s)
  • acodec=mpga sets the audio codec to mpeg audio (mp3). Audio does not work yet, this is a place holder.
  • ab=256 sets the bitrate of the transcoded audio (256 Kb/s)
  • scale=1 sets the scaling value
  • width=1280 sets the width of the transcoded video to 1280 pixels
  • height=800 sets the height of the transcoded video to 800 pixels
  • :rtp tells VLC that we want to use rtp protocol to send the encoder output to our receiver machine using Real Time Protocol.
  • dst= is the ip address of our destination/playback machine
  • port=1234 is the default port on the destination/playback machine
  • access=udp specifies UDP protocol
  • mux=ts sets multiplexing to mpeg-2 Transport stream

Now on the destination machine just open vlc, goto File/Open Network and by default the Media Resource Locator on top of the window should read udp:// and UDP/RTP with port 1234 should be selected. If it’s not select UDP/RTP (option 1) and put 1234 as the port number. Press Okay and you should see the video stream from the other machine (your server machine). That’s it….Opensource comes to rescue again :-)

How to uninstall almost any application in OSX manually

datePosted on 22:02, January 4th, 2008 by Many Ayromlou

Well, you learn something new everyday. Here is what I picked up today….If you ever install an application that came as a OSX package, there is a good chance that the installer has installed files all over your machine. There is also a good chance that the installer has left you a little gift — a way out if you like — in /Library/Receipts folder on your mac.

You see, if the author/packager has done their job correctly (most do), there is a Bill Of Material (known as a bom file) that is copied onto your system. In the example below I wanted to check the files that got installed on my machine by the MacFUSE installer so here are the commands I issued:
Brainiac:/ mayromlou$ cd /Library/Receipts/MacFUSE\ Core.pkg/Contents/
Brainiac:Contents mayromlou$ ls Info.plist PkgInfo Resources
Brainiac:Contents mayromlou$ lsbom

So in this case I cd to the folder for the application in question (under the /Library/Receipts folder) and go directly to the Contents Folder. Then I get a directory listing and notice that there is a Bill of Material file there. Then I proceed to issue the lsbom command which will decode the bom file and shows me the following output:
. 40755 0/0
./Library 41775 0/80
./Library/Filesystems 40755 0/0
./Library/Filesystems/fusefs.fs 40755 0/0
./Library/Filesystems/fusefs.fs/Contents 40755 0/0
./Library/Filesystems/fusefs.fs/Contents/Info.plist 100644 0/0 2591 1626887788
./Library/Filesystems/fusefs.fs/Contents/Resources 40755 0/0
./Library/Filesystems/fusefs.fs/Contents/Resources/English.lproj 40755 0/0
./Library/Filesystems/fusefs.fs/Contents/Resources/English.lproj/InfoPlist.strings 100755 0/0 6092 580475608
./Library/Filesystems/fusefs.fs/Contents/version.plist 100644 0/0 456 3975516369
./Library/Filesystems/fusefs.fs/Support 40755 0/0
./Library/Filesystems/fusefs.fs/Support/fusefs.kext 40755 0/0
./Library/Filesystems/fusefs.fs/Support/fusefs.kext/Contents 40755 0/0
./Library/Filesystems/fusefs.fs/Support/fusefs.kext/Contents/Info.plist 100644 0/0 1032 1833265120
./Library/Filesystems/fusefs.fs/Support/fusefs.kext/Contents/MacOS 40755 0/0
./Library/Filesystems/fusefs.fs/Support/fusefs.kext/Contents/MacOS/fusefs 100644 0/0 282292 3125657523
./Library/Filesystems/fusefs.fs/Support/fusefs.kext/Contents/Resources 40755 0/0
./Library/Filesystems/fusefs.fs/Support/fusefs.kext/Contents/Resources/MacFUSE.xcconfig 100644 0/0 42 965707547
./Library/Filesystems/fusefs.fs/Support/load_fusefs 104755 0/0 29212 3910787877
./Library/Filesystems/fusefs.fs/Support/mount_fusefs 100755 0/0 52008 3511781209
./Library/Filesystems/fusefs.fs/Support/ 100755 0/0 4419 3035817197
./usr 40755 0/0
./usr/local 40755 0/0
./usr/local/include 40755 0/0
./usr/local/include/fuse 40755 0/0
./usr/local/include/fuse/fuse.h 100644 0/0 28075 1689529217
./usr/local/include/fuse/fuse_common.h 100644 0/0 6623 3278924455
./usr/local/include/fuse/fuse_common_compat.h 100644 0/0 738 1569919976
./usr/local/include/fuse/fuse_compat.h 100644 0/0 8749 3548531510
./usr/local/include/fuse/fuse_darwin.h 100644 0/0 2304 4217317508
./usr/local/include/fuse/fuse_lowlevel.h 100644 0/0 40397 1846692219
./usr/local/include/fuse/fuse_lowlevel_compat.h 100644 0/0 7572 2140056707
./usr/local/include/fuse/fuse_opt.h 100644 0/0 7307 3645063899
./usr/local/include/fuse.h 100644 0/0 246 2097503619
./usr/local/include/ulockmgr.h 100644 0/0 701 3653182913
./usr/local/lib 40755 0/0
./usr/local/lib/libfuse.0.0.0.dylib 100755 0/0 272548 3600984730
./usr/local/lib/libfuse.0.dylib 120755 0/0 19 2829363220 libfuse.0.0.0.dylib
./usr/local/lib/libfuse.a 100644 0/0 861224 2222446251
./usr/local/lib/libfuse.dylib 120755 0/0 19 2829363220 libfuse.0.0.0.dylib
./usr/local/lib/ 100755 0/0 804 1483864331
./usr/local/lib/libulockmgr.0.0.0.dylib 100755 0/0 38900 610654515
./usr/local/lib/libulockmgr.0.dylib 120755 0/0 23 4013380549 libulockmgr.0.0.0.dylib
./usr/local/lib/libulockmgr.a 100644 0/0 41056 3770607053
./usr/local/lib/libulockmgr.dylib 120755 0/0 23 4013380549 libulockmgr.0.0.0.dylib
./usr/local/lib/ 100755 0/0 832 341285231
./usr/local/lib/pkgconfig 40755 0/0
./usr/local/lib/pkgconfig/fuse.pc 100644 0/0 276 3834070396

The listing above shows all the files that were installed by the MacFUSE installer, so now I can easily go through the list and remove the files (either command line or with Finder). Have fun uninstalling those uninstallable beasts :-).

Changing DNS hostname on OSX Server

datePosted on 13:17, December 15th, 2007 by Many Ayromlou
If you ever need to check the DNS hostname under OSX server here is the command:

$ sudo changeip -checkhostname
If you need to change it (ie: after a DNS table change) use the following command (for OD sites):
changeip /LDAPv3/
changeip also has a lot of other uses (ie: if you change the ip address of your machine you can use changeip to change the setting in the directory as well). Have a look at the man pages for more info.

If you’re having trouble kerberizing your Open Directory under OSX server then you are also most likely having hostname problems. Run the first command to check the hostname information and make sure “Current Hostname” and “DNS Hostname” in it’s output match. If they don’t use the second command to change (fix) it (assuming your DNS is working properly). Then you can go to Server Admin and under Open Directory/Settings press the Kerberize button that Pops up on the lower left.