Jun 192013
 

Sometimes it’s useful to write a bash script that do something like “Do this job, if it’s still running after XX second kill it”, how to implement this in a normal bash environment ?

Nothing simpler: Use the timeout shell command to achieve this.
From its info page:

timeout runs the given COMMAND and kills it if it is still running after the specified time interval

Let’s see how to use it.

Continue reading »

Flattr this!

Sep 182012
 

Today i was writing a bash script that should manage some input arguments, and so i studied getopt, this is a convenient and elegant way to manage input parameters in a bash script. With it you can define switch (present or not) or parameters with an option, thus making your simple bash script much more professional.

Let’s see how to use this command and its options.

Please note that on Linux there are two different ways of parsing command line arguments. There is an utility called getopt (man 1 getopt). This utility is available in all shells. Then in bash, there is another built-in tool for parsing arguments called getopts (it’s a built-in, so it doesn’t have it’s own man-page — try help getopts). In this article I’ll talk of the first one, after some problems with script not working in dash i prefer to use external small programs rather than bash built-in commands.

Continue reading »

Flattr this!

Aug 082012
 

Today I want to share with you some of my favorite features of bash, I called them hidden because I’ve discovered that a lot of people don’t know or don’t use them, but to be honest they are not so hidden after all, they are in the man page of bash, but how many of us have read it all ?

1) xkcdcom-149-2

Thanks to xkcd.com for this explanation.
In short this is useful when you need root access for a command and you forget to use sudo.
The parameter “!!” is substituted with the last run command.

Continue reading »

Flattr this!

3 Shell Information Tools for Linux

3 Shell Information Tools for Linux

Sometime is useful to have information on a system when you login into it via ssh or via a local terminal, or perhaps just to have a warmer welcome with some ASCII art and information on your system, on Linux there are many software that do this work, we can call them Shell information tools. […]

Etckeeper – Keep under control your configuration files !

Article based on the work of  Angelo D’Autilia  posted on Salug Journal in Italian. An useful tool for the management of a shared server is etckeeper. This software is a collection of bash scripts that allow you to control through a distributed revision system our directory /etc/ where there are the configuration files of most […]