Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Friday, March 23, 2018

Bash Functions

This post contains few functions, or tips I often use, so I keep them close.


Saturday, July 30, 2016

Ping-based Host Monitoring Script with Timestamps

In my previous post Server availability monitoring with email notifications I've used the same idea of monitoring. This script is a version 2.0 with some additional features:
  1. If you compare old and new version, you'll notice the script was completely rewritten. It's because I wanted it to run on my synology NAS.
  2. Next change is additional host states, instead of A-available and N-notAvailable I'm now using 2 additional states Going Up, Going Down. This will delay the notification about host state change and prevent frequent flapping of naughty hosts in network.
  3. Last feature added is hosts UP/DOWN times in notifications; see mail notification example:

Tuesday, January 27, 2015

Dynamic shell prompt

Dynamic shell prompt can change it's form according to some events going on on terminal. It can change e.g. color, if the previous command execution was unsuccessful, or it can display various information.
In this post, there is an example of such a prompt. It displays information, when you enter specified working directory.

The picture below shows my configuration:

This is achieved with setting a variable PROMPT_COMMAND which is evaluated every time you run a command. In my case, there is a condition, which looks for matching path.



# dynamic PS prompt
export PROMPT_COMMAND='PS1="$(if [ "$(pwd | grep /mnt/storage/backup_git)" ]; then echo "\\[\\033[32m\\]backup_git "; fi;)\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] "'