Tag Archives: linux

Shell Script to Get Last Character of a String

shell script

There are a couple of ways to extract the last character of a string within a shell script. The easiest way is if you are working on bash shell – as bash will get the job done without the help of any external utilities.

Linux / Windows: How to Retrieve Serial Number of Server

Sometimes I would need to retrieve the serial numbers of servers remotely – HP ProLiant and Dell PowerEdge servers to be precise. The normal way is to make a trip down to the server room and write down the serial numbers found on a sticker pasted on the server chassis. The other lazy (and smart) way is to retrieve the information from the command line!

Get Route Details for a Destination on Linux

To verify routing entries for a destination IP on a Solaris machine, I typically use the route get command. This will give the source IP address and Ethernet interface used by the kernel to reach the specified destination. On Linux however, the route utility does not support the get sub command.

How to Execute Shell Script on Logout

Sometimes I need to run a cleanup script automatically once I logout from a Linux or UNIX system. I normally use the script to cleanup my own temporary files.

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.