Tag Archives: linux

How to Catch Ctrl-C in Shell Script

There are times when you do not want users to stop a running shell script abruptly by sending the Ctrl-C key combination. There is no way to prevent users from doing that, but there is a way to catch or trap Ctrl-C key combinations in a shell script.

Linux: Enable IP Forwarding

unix linux

If you would like to turn a Linux machine into a router or a VPN server you will need to enable the IP Forwarding (aka routing) functionality as a first step. This functionality requires you to have at least 2 Ethernet interfaces connected to different networks or subnets.

Find Number of Hops Using Ping

In the computer networking field, traceroute is a diagnostic tool for displaying the hops and the round-trip time for each hop. Ping, on the other hand, computes round-trip times only from the destination point. But if you are just interested in finding out the number of hops to a destination and not the round-trip times, ping is an alternative utility to traceroute.

How to Get Linux Boot Time

Linux uptime command will show how long the system has been running. But if you want to find out the boot time of the system instead, you will have to perform a bit of arithmetic – subtract the output of the uptime command from the current time. Sounds too troublesome? There’s an easier way to do it using the Linux proc filesystem.

Unix: Print Directory Tree Structure

shell script

The tree command has been around in Windows for a very long time to print out the directory structure but this is still not available in most of the Unix variants. Most of the new Linux distributions do seem to have the tree command available.

Special Shell Variables

As I always have a tendency to forget the special variables used in shell scripts, I am going to document down the variables here.

Shell Script with Password Prompt

shell script

At work, I have a couple of shell scripts to perform LDAP queries. Initially the scripts were hard-coded with the login credentials of a read-only user. But as the scripts were enhanced to handle LDAP query updates, I realised that it was not a good idea anymore to hard-code the username and password as I was just inviting trouble. And the scripts will be a big NO during system audit.

Shell Script: Check If Weekend

I have some shell scripts that will perform certain actions only on a weekend (Saturday or Sunday). There are two ways to solve the “is it a weekend” logic.

K, Ki Key Conversion Tool for AUC / HLR

I have been looking for a tool to encrypt Ki values (into eKi) using AES encryption. Ki is a 128-bit value used in authenticating the SIMs on the mobile network.