BASH – The Bourne Again Shell amongst most if not all other shells allows each application to exit with a return code. Some shells and environments have limits on what range this integer can fall into. Something between 0 and 255 inclusive is always a safe bet. In BASH, the variable $? is populated with the return code of the last command to return control back to the shell. It is important to preserve the return code immediately after the application exits that we want to monitor, as subsequent commands will overwrite the variable. The ping tool returns 0 on success:
Now of course there are easier ways of achieving the above task, although I’ve laid out the script in this way hoping that the way I have laid it out illustrates capturing the code and preserving it beyond the ‘if’ that follows which would have overwritten it. Just as further illustration, calling ping invalid followed directly by echo $? shows a return code of ’2′ – obviously the return code for such a failure. Calling echo $? again immediately after shows a return code of ’0′ as the return code of ping was overwritten by the return code of the first echo statement. Bash builtins return codes to the shell as any other application would.
Tags: bash, host, monitor, ping, return code, script, shell, shell script, uptime, variable
mknod is a powerful command with which you can create block or character special files. If you view the man page, you’ll see that you can use it to create block device links and character device links. If you don’t know what these are then don’t worry. The purpose of this tutorial is to explore the FIFO (First In First Out) feature.
A FIFO literally does what it says on the box. The first piece of data to go in is the first piece of data to go out.
The usage of the command is:
Usage: /bin/mknod [OPTION]… NAME TYPE [MAJOR MINOR]
Where MAJOR and MINOR are for the special devices mentioned above.
(more…)
Tags: /bin/mknod, beej, block, C, cat, character, device, echo, fifo, first in first out, Linux, major, man, man page, minor, mknod, shell script, special files