programming

Like most sys admin, I’m lazy. I try to automate almost all things in order to save time. Inexperienced sys admin and help desk staff working under me finds all these tools useful. It saves their time and avoids security issues. Automation allows help desk staff to do things that they don’t have enough direct system knowledge to do themselves. However, selecting correct tool and applying correct methodology is very important.
[continue reading…]

The purpose of a debugger is to allow you to see what is going on inside another program while it executes. It is useful to find out what another program was doing at the moment it crashed. I know most people will recommend GNU gdb, Nemiver, Valgrind or IDE such as Eclipse. I use gdb when it is really required; otherwise I debug the old fashioned way using printf() or cout statements.
[continue reading…]

This may come handy while writing cross-platform scripts.

If you don’t want to commit to the idiosyncrasies of a specific shell running on a particular platform, try the Squirrel Shell. The Squirrel Shell provides an advanced, object-oriented scripting language that works equally well on UNIX, Linux, Mac OS X, and Windows systems. Write a script once, and run it anywhere.

Squirrel is a high level imperative/OO programming language, designed to be a light-weight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games.

=> Speaking UNIX: The Squirrel portable shell and scripting language

Twitter is a free social networking and micro-blogging service, that allows its users to send and read other users’ updates (also known as tweets). Now, you can build your own Twitter like service using trillr1.
[continue reading…]

Python 3.0 final officially released! From the announcement:

On behalf of the Python development team and the Python community, I am happy to announce the release of Python 3.0 final.

Python 3.0 (a.k.a. “Python 3000” or “Py3k”) represents a major milestone in Python’s history, and was nearly three years in the making. This is a new version of the language that is incompatible
with the 2.x line of releases, while remaining true to BDFL Guido van Rossum’s vision. Some things you will notice include:

* Fixes to many old language warts
* Removal of long deprecated features and redundant syntax
* Improvements in, and a reorganization of, the standard library
* Changes to the details of how built-in objects like strings and
dicts work
* …and many more new features

=> Download Python 3.0

fold is really nifty command line utility to make a text file word wrap. This is useful for large number of text files processing. There is no need to write a perl / python code or use a word processor.

fold command syntax

fold -sw {COUNT} {input.txt} > {output.txt}

Wrap input lines in each input.txt, writing to standard output.txt.

Where,

  • -s: break at spaces
  • -w: {COUNT} use COUN} as WIDTH columns instead of default 80.

For example, following command will wrap input.txt at 60 width columns:
$ fold -sw 60 input.txt > output.txt

A large number of files can be processed using for shell loop:

for i in *.txt
do
  fold -sw 65 $i > $i.output
done

I’ve already written a small tutorial about finding out if a file exists or not under Linux / UNIX bash shell. However, couple of our regular readers like to know more about a directory checking using if and test shell command.

General syntax to see if a directory exists or not

[ -d directory ]
OR
test directory
See if a directory exists or not with NOT operator:
[ ! -d directory ]
OR
! test directory

Find out if /tmp directory exists or not

Type the following command:
$ [ ! -d /tmp ] && echo 'Directory /tmp not found'
OR
$ [ -d /tmp ] && echo 'Directory found' || echo 'Directory /tmp not found'

Sample Shell Script to gives message if directory exists

Here is a sample shell script:

#!/bin/bash
DIR="$1"
 
if [ $# -ne 1 ]
then
	echo "Usage: $0 {dir-name}"
	exit 1
fi
 
if [ -d "$DIR" ]
then
	echo "$DIR directory  exists!"
else
	echo "$DIR directory not found!"
fi

A few weeks ago Linus Torvalds started his blog. Now, Guido van Rossum started to write a diary (blog). He is best known as the author of the Python programming language. In the Python community, Van Rossum is known as a ‘Benevolent Dictator for Life’ (BDFL), meaning that he continues to oversee the Python development process, making decisions where necessary. He is currently employed by Google, where he spends half his time working on Python development. You can read his blog here online including some hot tips about Python 3.0 🙂

WikiVS has published detailed comparison between MySQL and PostgreSQL. From the pages:

MySQL vs PostgreSQL is a decision many must make when approaching open-source relational databases management systems. Both are time-proven solutions that compete strongly with propriety database software. MySQL has long been assumed to be the faster but featureless of the two database systems, while PostgreSQL was assumed to be a more densely featured database system often described as an open-source version of Oracle. MySQL has been popular among various software projects because of its speed and ease of use, while PostgreSQL has had a close following from developers who come from an Oracle or SQL Server background.

=> MySQL vs PostgreSQL from the open comparison website.

Korn shell (ksh), a command-line interface for Unix. The main advantage of ksh over the traditional Unix shell is in its use as a programming language. Since its conception, several features were gradually added, while maintaining strong backwards compatibility with the Bourne shell.

IBM has published Korn shell scripting – A beginner’s guide:

Korn shell scripting can save you a lot of time and make your job so much easier. It can seem intimidating at first, but remember to always start out simple and build upon each and every script. Always follow the same steps: build your script header, define your variables, and error check your work. You just might find yourself trying to write a script for everything you do.

Korn shell scripting is something all UNIX users should learn how to use. Shell scripting provides you with the ability to automate many tasks and can save you a great deal of time. It may seem daunting at first, but with the right instruction you can become highly skilled in it. This article will teach you to write your own Korn shells scripts.