Tag Archives: shell script

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.

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.

Create a tar.gz File in a Single Command in Solaris

Solaris does not ship with the GNU tar and by default, the tar command in Solaris does not allow you to create gzip or bzip2 files, but only pure tarballs. You will need to create a tar file first and then compress the tarball with the gzip command.

How to Get the Home Directory of an User

To perform disk usage monitoring of users on a UNIX system, you will, first of all, need to determine the home directories of the users. You might ask, “Aren’t all the user home directories found under /home?”. Well, typically yes, but it’s not always true.

Shell Script: Calculate Yesterday’s Date on UNIX

shell script

There are times when you will need to calculate yesterday’s date in a UNIX shell script to run some date sensitive cron jobs. There are currently no standard command line tools in UNIX to perform such date arithmetic.