The world is my backyard.
Random header image... Refresh for more!

One command to rule…. alright, just return an IP

One of my friends who is into networks always joke, as why there is no single Unix command to return only the IP address and nothing else. Here is a script that just does that one thing and nothing else.

#!/usr/bin/env bash # Arvinder Singh Kang # askang@olemiss.edu # Version 0.1 - 2009-06-02 # ipaddress: This snippet returns the ipaddress of the current computer. Store in a directory which is in the PATH, and make it executable by running "chmod +x ipaddress". # Running command ipaddress should return ipaddresses of this machine.

ifconfig  | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'

December 8, 2009   2 Comments

Automating Drupal workflow using Git and Drush

Update Nov 11, 2009: Updated the script to accept username and server name as arguments and to print syntax help if no argument is passed. It would eliminate to modify script for different servers.

Drupal rocks for some things, its deployment sucks! As I automate my drupal workflows better, I should post them one by one.

Following is the my bash script recipe, for installing drupal, checking it into a git repository and replicating it remotely.

The second piece of puzzle should be automating MySQL backup and deployment using either Capistrano or Vlad.

[Read more →]

October 29, 2009   3 Comments

A simple shell trick

Here is shell a trick that I used lately.

Before moving to new system (where I enforce quotas on all home folders), I had portable home directories for all the users on my shared server storage. The old setup did not strictly apply the quota limits on all users. Some of the users had large home folders and a couple of them logging on different systems, would fill up the whole hard disk on that system.

Two find how much space each user was using on the server, I ran the following command in their home directory.

$ du -chd -1 > $HOME/user_space_report.txt

Simple.

August 20, 2008   No Comments

Jukebox in a single line

If you are like me, who starts starts iTunes with default library and realize you have heard the same song 8 times in the last week, here are two one-line-Jukebox scripts for you. The scripts randomly choose and play songs right from the command line.

Before using the script make sure you have an mp3 player installed. I have installed lightweight mpg123, however you can use any player. I would recommend mplayer for Linux.

While running the scripts, I pass ~/Music folder argument. Change the path to point to folder where you store your mp3s.

First one is in Ruby, and shamelessly inspired by Kevin Baird’s book.

Open a text editor and save this script. I named it shuffle_play.rb. (You need to have ruby installed on your system. Installed on Leopard and most Linux distributions by default.)

#!/usr/bin/env ruby -w
ARGV.sort_by{ rand }.each {|file| system("mpg123 \"#{file}\"")}

To run the jukebox

ruby shuffle_play.rb ~/Music/*.mp3

For the second, I ported above script to bash, which is even more simple and can run on any Linux or OS X. Lets name the script shuffle_play_shell.sh

#!/usr/bin/env bash
n=0;for songs in "$@" ; do song_array[n]=$songs ;((n++)) ; done; for ((i=0;i<$n;i+=1));do number=$RANDOM; let "number %= $n"; `mpg123 "${song_array[number]}"`; done

To run the jukebox

source shuffle_play_shell.sh ~/Music/*.mp3

Update: The second one is not completely random. It will choose n random songs out of n songs. However it does not checks if each song is played at-least once, thus chances of songs getting repeated. Any suggestions?

June 28, 2008   No Comments