Showing posts with label tools. Show all posts
Showing posts with label tools. Show all posts

Saturday, November 29, 2014

Homebrew cheat sheet and workflow

If you are a Mac owner and a serious *NIX user, you're probably aware of Homebrew.

I have a few of my favorite tools installed with brew and I like to keep my "Cellar" clean and up-to-date. Here's my commonly used commands and my typical workflow.

Never forget about man's best friend - "man". Use man to get the list of commands and options that can be used with brew:

man brew

To list software you currently have installed with version numbers, use:

brew list --versions

To see just the software, which is not a dependency of another:

brew leaves

To keep the Homebrew itself up-to-date, and fetch the newest version from GitHub:

brew update

After updating the brew, check which formulae have an updated version available, display detailed version information to see if you have more than one older version laying around:

brew outdated --verbose

See any app that you no longer need and want to get rid of them? Check the dependencies for all installed formulae:

brew deps --installed

For even more detailed picture, show the dependencies for all installed formulae as a tree:

brew deps --installed --tree

As a final precaution before removing a formula, see what other installed formulae use it as a dependency:

brew uses --installed formula

Uninstall formulae and all their older versions:

brew remove --force formulae

Upgrade remaining formulae:

brew upgrade

Show what will be removed by cleanup command, but do not actually remove anything:

brew cleanup -ns

Clean the "Cellar" removing any older versions of installed formulae and clearing old downloads from the Homebrew download-cache. Additionally, scrub the cache, removing downloads for even the latest versions of formula, which are downloaded, but not installed:

brew cleanup -s

Thursday, March 13, 2014

Add time stamp to a file name from CLI

I often find myself in need to append a time stamp to a file name, but always forget the right command line parameters. Here's a quick reminder to myself on how to do just that.

mv filename filename-$(date '+%FT%T')
or
mv filename filename-$(date '+%s')

For those who want to know the details, here's the break down.

Sunday, August 19, 2012

Install adb and fastboot on OS X

There are plenty of packages floating around the Internet with just the adb and fastboot utilities for OS X, but I prefer installing those (and few other android utilities) on OS X is via Android SDK. This way you know exactly what you're getting and it's easy to can keep them up-to-date with Android SDK Manager.

First download the latest Android SDK package from http://developer.android.com/sdk/index.html (android-sdk_r20.0.3-macosx.zip at the time of this writing).

Change into your download directory and unzip archive into your preferred location. I like my home directory so I run:

unzip android-sdk_r20.0.3-macosx.zip -d ~

This creates a android-sdk-macosx directory in our home directory. Now run android application inside the tools directory to open Android SDK Manager (ASM).

~/android-sdk-macosx/tools/android

ASM will connect to various repositories and present you with all possible Tools, Platforms and Add-Ons that could be downloaded and installed. Since we're only interested in few specific tools, deselect all except "Android SDK Tools" and "Android SDK Platform-tools" packages and then install / upgrade them.


Note: to accelerate checking for updates during future runs, go to "Tools"->"Manage Add-on Sites..." and click on "Disable All" button in "Official Add-on Sites" tab. From now on ASM will check only the default repository containing tools and APIs.

Now we'll add android tools to our PATH to make executing them more convenient. Create or edit .bash_profile file in your home directory to contain these lines, just don't forget to replace YOURUSERNAME with your actual user name:

ANDROID_TOOLS=/Users/YOURUSERNAME/android-sdk-macosx
export PATH=${PATH}:${ANDROID_TOOLS}/platform-tools:${ANDROID_TOOLS}/tools

Done.

Sunday, August 5, 2012

Google Apps email, GoDaddy hosting and SPF records

The other day I was setting up another web site using GoDaddy for hosting and DNS and Google Apps for email. The two Gs make a great combo since GoDaddy allows for quick domain verification right within Google Apps admin view, while their configuration tool automatically creates the necessary MX records for Google Apps. The deployment is as fast as it gets.

The issue arose when I tried to send test email from the web application using Google's SMTP servers. Apparently GoDaddy rejects all outgoing SMTP connections to any servers but its own relay-hosting.secureserver.net. Not much can be done about that,  so I guess I just have to configure my SPF records to define which servers are authorized to send emails on behalf of my domain.

For Google Apps it's a well documented procedure, just add the following TXT record:

"v=spf1 include:_spf.google.com ~all"

Now what settings to add for GoDaddy's servers? GoDaddy's SPF wizard would have me use something like this:

"v=spf1 a mx include:smtp.secureserver.net ~all"

Since I've changed my MX servers to Google's and they won't be sending any mail, the "mx" mechanism could be dropped. Same goes for "a" mechanism since, as I discovered, GoDaddy does not allow its shared hosts to send any email directly. Let's dig into the "include:smtp.secureserver.net" portion and see what's inside...

dig smtp.secureserver.net -t txt

Here's the contents of TXT record: "v=spf1 include:spf.secureserver.net -all". OK, let's dig deeper...

dig spf.secureserver.net -t txt

Now we get a whole set: "v=spf1 include:in.spf.secureserver.net include:in2.spf.secureserver.net include:ext1.spf.secureserver.net include:ext2.spf.secureserver.net include:ext3.spf.secureserver.net include:mon.spf.secureserver.net include:exch.spf.secureserver.net -all". Yikes! Do I have to check all of these one by one?

Luckily, there's an easier way with a free online tool called SPF Parser. Just paste smtp.secureserver.net into the text field and get the entire list of all A and relevant SPF records recursively parsed.

The output contained IP address of GoDaddy's relay server, so in theory it should work, so my final SPF record becomes:

"v=spf1 include:_spf.google.com include:smtp.secureserver.net ~all"

Once new record is in place, validate it over at Scott Kitterman's site, where you can see what your domain is currently reporting, whether it's valid and whether an email sent from certain IP shall pass of fail SPF verification.

Monday, April 16, 2012

Convert Unix, Windows, Mac line endings using OS X command

Today I had to copy some MySQL data from Debian server into test environment on my MacBook. While importing data from tab delimited text files, I noticed warnings that data in the last column of several tables was being truncated. I looked at the tables and noticed MySQL doing some very strange formatting when printing them. It looked almost as if last column was padded with a bunch of white space. I opened import file in TextWrangler and it appeared fine, but when I looked in document options, I saw this:

 

The good ol' EOL (end-of-line) character...

Different operating systems use different characters to mark the end of line:
  • Unix / Linux / OS X uses LF (line feed, '\n', 0x0A)
  • Macs prior to OS X use CR (carriage return, '\r', 0x0D)
  • Windows / DOS uses CR+LF (carriage return followed by line feed, '\r\n', 0x0D0A)
I'm guessing the person who sent me those files first transferred them to his Windows machine in ASCII mode, so newline characters got automatically converted during transfer.

Since some of the files were very big, instead of changing line endings in TextWrangler I decided to use command line (shocking, I know).

First I executed
cat -v file-name
to confirm existence of the dreaded ^M (carriage return) at the end of every line, and then ran
tr -d '\r' < file-name > file-name-unix
to generate new files without CR characters.

tr (translate character) is a nice little utility that does just that, substitutes one character with another or deletes it (like in my example). It's available on pretty much any *nix distro so no need to install additional software.

Tuesday, November 8, 2011

Make VMware ESXi 5 LiveUSB installer on Mac OS X

I have used UNetbootin in the past to move VMware ESXi 4.0 installer to USB flash drive, since then, however, this great tool now also works on Mac OS X (in addition to Linux and Windows). Since my MacBook Pro is the only other computer I own at the moment, this is a great new development. Now let's do the same thing with ESXi 5!

One little note: UNetbootin won't see your USB drive if it's formatted as Mac OS Extended (Journaled) with GUID Partition Table. That's easy to fix with Disk Utility:
  1. select your USB drive from the list of devices on the left
  2. click on the "Erase" tab on the right
  3. choose "MS-DOS (FAT)" format
  4. click "Erase" button

Now on to create the LiveUSB VMware vSphere 5 installer. Open UNetbotin, enter your Mac administrator password and then:
  1. select "Diskimage" option
  2. browse to and select your previously downloaded VMware ESXi 5 Installer iso
  3. make sure your installing onto correct USB drive
  4. click "OK" and wait for wizard to complete

When wizard asks whether you want to overwrite menu.c32 file, answer "No". This will allow you to boot directly into ESXi installer and bypass Syslinux default blue boot menu.


Finish, eject and you're ready to install your sparkling new Hypervisor.

Update: as you can see in comments below, it seems these steps are not quite sufficient to boot ESXi installer. I also had to enable UEFI boot option in BIOS, while Raul added a kickstart configuration.

Tuesday, October 5, 2010

Read a random line of text from file in Linux

CLI

There are many ways to achieve this, but this is probably the simplest since you most likely already have all the necessary components installed.

On Ubuntu it's the "shuf" command from "coreutils" package. It's original purpose is to shuffle the lines passed to it, or as its description says: "write a random permutation of the input lines to standard output". However, with one of the arguments you can limit the number of lines it returns, so if all you need is a single line from a given text file, juts run:

$ shuf –n 1 list.txt

where argument –n tells shuf to print only one random line from file list.txt

Friday, September 24, 2010

My must-have free Mac OS X apps

There are a lot of lists like this on the web, but every user's needs are slightly different, so here's a list of my favourite free Mac OS X apps that I install and use on all my Mac, and where possible, Linux and Windows computers.

Unarchiver

unarchiver This puppy can open pretty much any archive/compression format out there: Zip, Tar-GZip, Tar-BZip2, RAR, 7-zip, LhA, StuffIt and more. I nice touch is an option to automatically delete archive file after it has been extracted.

Download: http://wakaba.c3.cx/s/apps/unarchiver.html

TextWrangler

textwrangler If you do any kind of programming or just like to work with plain text files, this text editor is a must. There are better coding tools out there, but few are this cheap.

Download: http://www.barebones.com/products/textwrangler/

Burn

burn Forget bloated and expensive burner apps, here's a simple bare bones burner that can easily handle 99% of your CD/DVD burning needs.

Download: http://burn-osx.sourceforge.net/Pages/English/home.html

Adium

adium For chatting online nothing beats a good multi-protocol Instant Messenger. Adium is my Pidgin for Mac, talk to your contacts on MSN, AOL, GTalk, Yahoo, ICQ, IRC, Jabber, Facebook and more all from one client.

Download: http://adium.im/

Cyberduck

cyberduck Great app for transferring files. It supports FTP, SFTP, SCP, WebDAV and, as of recently, even Amazon S3 and Google Docs.

Download: http://cyberduck.ch/

Transmission

transmission Technically I don't use this app on any of my Macs anymore, but that's only because I run it on my Linux headless server 24x7. If you don't already do something similar, this BitTorrent app is definitely a must.

Download: http://www.transmissionbt.com/

Dropbox

dropbox This is a fantastic little utility I use on ALL my computers (Mac, Linux or Windows) to keep a small set of files in sync and backed up to the cloud. Any changes to these files will be automatically pushed to all computers, great for important docs that you frequently work on from multiple machines.

Download: http://www.dropbox.com/referrals/NTY1MDg4MTk

KeePassX

keepassx This is a Mac version of an awesome password safe application KeePass. It stores all your important passwords in its encrypted database. All you have to do is remember one strong master password, KeePassX will generate and remember passwords for everything else. Combine it with Dropbox and you'll have instant access to your password database from any of your computers or smart phones.

Download: http://www.keepassx.org/

VLC

vlc The ultimate video player/server that can play practically any video/audio format out there without you lifting a finger. It is much more than just a player, though, you can also re-encode or stream your videos to any machine on your LAN. I once used it to stream a DVD playing on my desktop to a laptop without DVD drive, which was connected to a video projector next door.

Download: http://www.videolan.org/vlc/

Perian

perian If you prefer to play your movies on the pre-installed QuickTime, Perian is your best friend. It gives you power to play many video/audio formats directly in QT.

Download: http://perian.org/

Handbrake

handbrake For times when you need to backup/rip your DVDs or do some format shifting, few apps come close to ease of use of Handbrake.

Download: http://handbrake.fr/

Growl

growl Not critical, but nice to have utility that makes system and application pop-up notification a lot nicer.

Download: http://growl.info/

Seashore

seashore This is an image editor, it's simple and has limitations, but it's free!

Download: http://seashore.sourceforge.net/The_Seashore_Project/About.html

Wednesday, September 22, 2010

Convert .png to .gd2 for Nagios status map

nagios-150x150

If you ever tried to make Nagios web interface look a little nicer by adding some custom host or service icons, you have probably came across collections of icon packs at Nagios Exchange. You have also noticed an unusual .gd2 extension on some of the images and realized that without this format icons don't display properly on Status Map. I was doing exactly that the other day and couldn't find the icons I needed, so I ended up creating some myself. Here's how to convert a PNG image into .gd2 (GD Graphics Library format).

On Ubuntu install libgd-tools package, it will contain a pngtogd2 app. To convert file.png to file.gd2 use:

$ pngtogd2 file.png file.gd2 0 1

Once you have your .png or .gif and .gd2 images, I tend to use 40x40x8bit images with transparent background, place them in your /usr/local/nagios/share/images/logos/ directory (if you installed Nagios from source) and add these properties to your host or service definition:

define host{
        ...
        icon_image              ubuntu.png
        statusmap_image         ubuntu.gd2
        ...
        }

Saturday, July 24, 2010

The All-in-One Live USB

MultiBoot-ISOs

I have mentioned various ways to create a Live USB from a LiveCD before, but the following method, in my opinion, takes the prize. Once again great guys at pendrivelinux.com put together tools and steps necessary to Boot Multiple ISO from USB.

I have modified the process a bit to make the result suite my needs better, and encountered a few "gotchas", so as usual here are my notes.

Friday, July 9, 2010

BitTorrent and zsync FTW

My current favourite (and it seems almost everyone else's) Linux distro is Ubuntu. I use it on my home server, on virtual machines at work, I even carry it on my USB stick. I find that the easiest, and probably the fastest, way to download Ubuntu is via BitTorrent. Using BitTorrent to download Open Source software is also a nice way to show your appreciation - you reduce project's bandwidth costs and help creators to distribute their product. This is especially true during the stable release time, when everyone rushes to get the latest release and direct downloads slow down to a crawl. This is the perfect time to use P2P, since hundreds of people already have the file you want and are willing to share it with you.

BitTorrent is not a silver bullet, however. It's only good when the file you want is a popular one. For example here's a some tracker stats for two Ubuntu releases, 10.04 is a stable release from a couple months back and maverick is the latest alpha:

File Seeders Leechers
ubuntu-10.04-dvd-i386.iso 1391 123
ubuntu-10.04-server-i386.iso 968 20
maverick-dvd-i386.iso 8 5
maverick-server-i386.iso 10 0

Not a lot of people care about the alpha release, so there are very few seeders and leechers. Since number of peers is low, P2P download will be slow and you might be better off just downloading the file directly. In Ubuntu's case there is a better solution - zsync.

Wednesday, July 7, 2010

Universal USB Installer

portable-linux-usb

In my last post I mentioned UNetbootin – a great tool for Windows and Linux that allows you to create bootable Live USB drives for Ubuntu, Fedora, and other Linux distributions (VMware ESXi) without burning a CD. Here's another such tool, but with few extra features added.

Universal USB Installer is a Live Linux USB Creator that allows you to choose from a selection of Linux Distributions to put on your USB Flash Drive. The Universal USB Installer is easy to use. Simply choose a Live Linux Distribution, the ISO file, your Flash Drive and, Click Install. Other features include; Persistence (if available), and the ability to format the flash drive (recommended) to ensure a clean install. Upon completion, you should have a ready to run bootable USB Flash Drive with your select Linux version installed.

I particularly like the "Persistence" feature to create Linux LiveUSB that allows me to save data changes back to the USB storage device instead of leaving the information in system RAM. This data can then be recovered and used again on subsequent boots, even when booting from different machines. Now I always have a bootable Linux USB in my pocket.

Saturday, June 26, 2010

Quickly create VMware ESXi 4 LiveUSB

I recently discovered that it's possible to create a VMware ESXi 4 install USB using nothing but UNetbootin and official VMware ESXi 4 ISO file. Why would I want to do that? So I can install ESXi on servers without CD/DVD drives, they have become quite common lately. USB install is much faster than installing from optical media, and you save environment by not wasting a blank CD on a software version that will become outdated in three months or so.

In the past I have used a great little Bash script by Varazir that allows you to not only make a bootable USB with ESXi on it, but can also customize and merge various drivers into the install image. However, if all you need is a vanilla install, UNetbootin makes it a lot easier and works on both Windows and Linux platforms.

Just choose the "Diskimage" option and browse to your VMware ISO and you'll have a installation USB drive in no time.

unetbootin

Saturday, May 29, 2010

Verify your downloads with checksums

lock-150

If you frequently download large files, such as installation media or LiveCDs, you might have encountered a situation where a file becomes corrupt during the download. You haven't? Let me paint a picture for you.

Your boss wants you to urgently deploy new ESXi server with all the latest updates and he wants it done yesterday. You grab the latest ISO release from the web and, after patiently waiting for it to download, burn it on a CD. You head to the server room, load the CD and… half way through install it complaints about media being corrupt. What happened? Was it the download? Failed burn session? Defective CD drive? Now you have to re-download the image and do it all over again and by now it's 4:30pm on Friday.

I have been there and can show you how to eliminate at least one unknown from the story above. You could verify whether file you downloaded is the same as the file posted on the web site. The process is called checksum or hash sum verification and allows you to check the integrity of your data.

Many sites will provide MD5, SHA1 or SHA256 checksum of the distributed file. All you have to do is compare it to the checksum of the file you have downloaded. How to do that? Here are two ways I use most often...

Friday, May 7, 2010

Some VMware gotchas

Had to troubleshoot a couple of VMware ESXi related errors at work this week, noting them here for my future self or anyone else looking for solution.

First problem occurred when I was moving a a 64bit SLES 9 virtual machine to a newly provisioned ESXi test host. The server in question was HP ProLiant DL360 G5 with Intel Xeon 5150 CPU. The CPU supports 64bit and VT, but when I started the virtual machine I got the following error:

Your CPU does not support long mode. Use a 32bit distribution.

Apparently the Virtualization Technology (VT) feature was not enabled in BIOS and ESXi could not run a 64bit guest OS without it. Pretty simple fix: reboot and reconfigure the BIOS settings to enable CPU's VT feature.

Next problem occurred when I upgraded one of the virtual machines. This VM was running 32bit Ubuntu 8.04 Hardy JeOS with VMware Tools Operating System Specific Package (OSP). I uninstalled the OSP using apt-get, upgraded the kernel and then attempted to re-install VMware Tools using .tgz package, but was greeted with the following error:

VMware Tools cannot be installed, since they have already been installed using
a package-based mechanism (rpm or deb) on this system. If you wish to continue,
you must first remove the currently installed VMware Tools using the
appropriate packaged-based mechanism, and then restart this installer

Execution aborted.

I double and triple checked, all VMware packages were removed, so what's the deal? After looking into the installation script vmware-install.pl, I saw that it checks for existence of DSP marker file /usr/lib/vmware-tools/dsp and displays the above message if file exists. I found that file being the sole resident of the /usr/lib/vmware-tools directory so I simply removed the file and the directory. Not sure why this file was left behind, but after that I was able to proceed with installation.

Monday, April 19, 2010

Import virtual appliance without vSphere client

ovftool-150

Since I don't have a Windows or even a non-Mac GUI machine at home, I have been looking for an easy way to import/export VMs and virtual appliances to/from my Whitebox ESXi server without VMware vSphere/Virtual Infrastructure (VI) client or Standalone Converter.

The solution came in the form of VMware Open Virtualization Format Tool, ovftool for short. This command line utility comes in Windows or Linux flavours and allows you to quickly probe, convert, compress, export and import virtual machines. Here are some of its feature highlights:

  • Supports both import and generation of OVA packages
  • Directly converts between any VI, VMX, or OVF source format to any VI, VMX, or OVF target format
  • Accesses OVF sources using HTTP, HTTPS, or FTP, or from a local file
  • Deploys and exports vApp configurations on vSphere 4 targets
  • Provides options to power on a VM after deployment, and to power off a virtual machine before exporting
  • Show information about the content of any source in probe mode
  • Provides context sensitive error messages for vSphere sources and targets, showing possible completions for common errors, such as an incomplete vCenter inventory path or missing datastore and network mappings
  • Provides an optional output format to support scripting when another program calls OVF Tool

Exactly what I need. I downloaded and installed Linux version to my headless Ubuntu server and was able to quickly deploy a sample virtual appliance to my ESXi server with the following command:

$ ovftool /path/to/test.ova vi://root@esxi.lan

For a slightly more interesting test I renamed the VM and told it to power on after import:

$ ovftool –-name=NewNameForVM –-powerOn /path/to/test.ova vi://root@esxi.lan

Now to power off a VM and export it as a Virtual Appliance:

$ ovftool –-powerOffSource vi://root@esxi.lan/ResourcePoolA/someVM01 /path/to/template.ova

For more documentation see VMware site.

Sunday, March 21, 2010

Creating video DVD iso file using Linux CLI

dvd-150

Recently I had to create a video DVD iso image from a bunch .VOB files using Linux command line. I found this extensive tutorial on both how to create and burn an image file using command line. Here is a quick summary.

First, create VIDEO_TS and AUDIO_TS folders, if you don't already have them. Apparently some DVD players will not play a DVD if it doesn't have this particular directory structure.

In my case I had just .VOB, .IFO and .BUP files with no directory structure, so I copied all files to VIDEO_TS folder and left AUDIO_TS empty.

To create ISO I used a mkisofs command like so:

$ mkisofs -dvd-video -o mydvd.iso -udf /path/to/filedir/

Where "mydvd.iso" is the name of my future ISO file and "/path/to/filedir/" is the directory containing my VIDEO_TS and AUDIO_TS folders.

Just a little while later my ISO image file was ready. Just in case I checked to make sure that VIDEO_TS.IFO file had the lowest sector number like so:

$ isoinfo -i mydvd.iso -l

Now burn!

Saturday, March 6, 2010

Add torrents to Transmission from Firefox

Just discovered a neat Firefox extension called Autotrans. It allows to send a torrent/magnet link from a web page straight to Transmission server via RPC.

Until now I had to right-click the link to torrent file, choose "Copy link location", open a new tab, type the URL to Transmission's Web UI, click "Open" button, paste the torrent link and click "Upload" button. Now it's simply a right-click on the link and select "Torrent it!". Bam!

Add-on configuration is pretty straight forward. Enter the IP/host name of the server the Transmission daemon is running on (you can even enter multiple daemons). If your daemon requires authentication, you can enter username and password. If you want, you can tweak values for AJAX timeout and retry count. There is also an optional menu item and status bar icon that takes you to Transmission web interface. The Autotrans is also smart enough to only show the context menu when link is a torrent/magnet link.

Wednesday, March 3, 2010

Making Pageant automatically load keys on startup

So I have a few private keys I generated for Public-Key SSH authentication. In Windows I manage SSH keys with Pageant - an SSH authentication agent for PuTTY. PuTTY is an awesome SSH/Telnet client for Windows that also comes with a suite of helper utilities like key generator and agent.

My work week starts like this: I log into my Windows workstation, open Pageant and load my keys one after another. Since the keys are encrypted I have to enter a password for each key. Once the keys are in memory I can securely log into multitude of Linux servers (that have the public key) without enduring their login prompt each time. Pretty nice, but there is still some room for improvement.

Wednesday, August 26, 2009

Clear temp OS files from your USB drive

One of the comments on the previous post reminded me of another free useful (Windows) tool - USBDriveFresher.

If you often use your USB drive between Mac, Windows and Linux operating systems, you might have noticed small, but numerous hidden system files left behind (Mac OS is particularly notorious for this). This simple app will automatically remove all files like .Trashes, .Spotlight-V100, .ds_store, ._*, thumbs.db and any others you specify.

Download: affinity-tools.com