10 Tools To Add Some Spice To Your UNIX Shell Scripts

Posted on in Categories Linux, Shell scripting, UNIX last updated April 19, 2010

There are some misconceptions that shell scripts are only for a CLI environment. You can easily use various tools to write GUI and/or network (socket) scripts under KDE or Gnome desktops. Shell scripts can make use of some of the GUI widget (menus, warning boxs, progress bars etc). You can always control the final output, cursor position on screen, various output effects, and so on. With the following tools you can build powerful, interactive, user friendly UNIX / Linux bash shell scripts.

FAQ Updates – Nov/13/2010

Posted on in Categories FAQ last updated November 13, 2009

Our FAQ section is updated in last few days with new howtos:

  • Linux Network IP Accounting – I need to know how much data are transmitted on my ppp0 network or eth0 Internet links? How do I set IP accounting by address such as 123.1.2.3 and 123.1.2.4? How do I set IP accounting per Apache virtual domain? How do I set accounting by service port (http, smtp) and protocol (tcp, udp, icmp)? How do I record how much traffic each of the clients computer is using?
  • Linux / UNIX: DNS Lookup Command – How do I perform dns lookup under Linux or UNIX or OS X operating systems without using 3rd party web sites for troubleshooting DNS usage?
  • Linux: Find Out Which Process Is Listening Upon a Port – How do I find out running processes were associated with each open port? How do I find out what process has open tcp port 111 or udp port 7000 under Linux?
  • Google Apps Domain Create SPF Records For BIND or Djbdns – I work for a small business and outsourced our email hosting to Google. However, I noticed that spammers are using our From: First Last to send their spam messages. All bounced messages come to our catch only account. How do I stop this? How do I validate our domain using SPF? How do I configure a SPF for Google Apps domain using BIND 9 or djbdns?
    Mac Os X: Mount NFS Share / Set an NFS Client – How do I access my enterprise NAS server by mounting NFS filesystem onto my Mac OS X based system using GUI and command line based tools?
  • Explains: echo Command (echo $”string”) Double-quoted String Preceded By a Dollar Sign – I noticed that many shell scripts in /etc/init.d/ directory use the following syntax – echo $”Usage $prog start|stop|reload|restart”. Why a double-quoted string preceded by a dollar sign ($”string”) using the echo command under Linux / UNIX bash scripts?
  • Get intimated about our new howtos / faqs as soon as it is released via RSS feed.

How To Write Object-Oriented Shell scripts For Multiple Platforms

Posted on in Categories Howto, Linux, programming, Shell scripting, Sys admin, UNIX last updated January 19, 2009

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

How to: Run All Shell / Perl / Python Scripts in a Directory

Posted on in Categories Linux, Shell scripting, Sys admin, Tips, UNIX last updated October 12, 2007

I’ve directory called /home/vivek/scripts/daily with over 25 perl / shell / python scripts for managing daily tasks. One day for some weird reason my crond died and I did not noticed the incident for 2 days.

Now crond is started and I’d like to run all those scripts. Here is a quick for loop running all scripts in a directory called ~/scripts/daily/:

for s in ~/scripts/daily/*;do [ -x $s ] && $s || : ;done

Above script will run each and every executable script it finds in a directory.

Update: As pointed out by jeff (see below), you can use run-parts shell script for the same purpose:
$ run-parts ~/scripts/daily/*

Linux / UNIX: Python programming tutorial for system administrators

Posted on in Categories Beyond nixCraft, Howto, Linux, Sys admin, Tips, UNIX last updated September 6, 2007

Generally I use Perl and Shell script for automation or to make system administration easier for me. Python is an interpreted, interactive, object-oriented programming language that combines remarkable power with very clear syntax. Python runs on Windows, Linux/Unix, Mac OS X, OS/2, Amiga, Palm Handhelds, and Nokia mobile phones.

You can easily adopt Python to manage UNIX and Linux systems while incorporating concepts of good program design. Python is an easy-to-learn, open source scripting language that lets system administrators do their job more quickly. It can also make tasks more fun:

As a system administrator, you run across numerous challenges and problems. Managing users, disk space, processes, devices, and backups can cause many system administrators to lose their hair, good humor, or sanity. Shell scripts can help, but they often have frustrating limitations. This is where a full-featured scripting language, such as Python, can turn a tedious task into an easy and, dare I say it, fun one.

The examples in this article demonstrate different Python features that you can put to practical use. If you work through them, you’ll be well on your way to understanding the power of Python.

=> Python for system administrators

Getting Yesterdays or Tomorrows Day With Bash Shell Date Command

Posted on in Categories Howto, Linux, Shell scripting, Tips, UNIX last updated June 17, 2007

When invoked without arguments, the date command displays the current date and time. Depending on the options specified, date will set the date and time or print it in a user defined way. I’ve seen many sysadmin writing perl scripts for calculating relative date such as yesterdays or tomorrows day. You can use GNU date command, which is designed to handle relative date calculation such as:

  • 1 Year
  • 2 Days
  • 2 Days ago
  • 5 Years