Couple of years ago I googled for a simple bash IRC logging bot that I could start on my router to log some channels. I've found a very simple script that worked but didn't handle PINGs from the server. So I extended it a bit trying to keep it as simple as possible.
Thoughts and ideas about programming, scripting, automation, electronics, gadgets, web and technology
Friday, June 10, 2011
Thursday, March 3, 2011
Encrypting with the openssl in bash
With a bit of commandlinefu it becomes easy to encrypt and decrypt files with the strong 256 bit aes algorithm using openssl.
Add the following into your ~/.bashrc
# crypting functions function encrypt { if [ -t 0 ]; then # interactive local fname="$1" shift openssl aes-256-cbc -salt -in "$fname" -out "${fname}.enc" $@ else # piped perl -e 'use IO::Select; $ready=IO::Select->new(STDIN)->can_read();' openssl aes-256-cbc -salt $@ fi } function decrypt { if [ -t 0 ]; then # interactive local fname="$1" shift openssl aes-256-cbc -d -in "$fname" -out "${fname%\.*}" $@ else perl -e 'use IO::Select; $ready=IO::Select->new(STDIN)->can_read();' openssl aes-256-cbc -d $@ fi }and source it to let changes take effect (source ~/.bashrc).
Labels:
bash,
encrypting,
openssl
Thursday, January 27, 2011
collectd-mod-exec Part 5
Part 1
Part 2
Part 3
Part 4
In this final part I'm publishing a real world example of the collectd-exec usage - weather info collecting script.
I'm using yahoo weather api to get weather information because it sends back very concise xml formatted text file which is only 2k in size. The weather info is updated once per hour so I've added special logic to retrieve it once per hour and feed same values in between.
Part 2
Part 3
Part 4
In this final part I'm publishing a real world example of the collectd-exec usage - weather info collecting script.
I'm using yahoo weather api to get weather information because it sends back very concise xml formatted text file which is only 2k in size. The weather info is updated once per hour so I've added special logic to retrieve it once per hour and feed same values in between.
Labels:
bash,
collectd-exec,
OpenWRT,
weather
Wednesday, January 26, 2011
collectd-mod-exec Part 4
Part 1
Part 2
Part 3
There is only one thing left to explain - how to get notified if some values go out of scope. As an example I'm going to send notification emails if CPU temperature reaches 57 degree Celsius. This could be implemented with only one additional if statement and this would work perfectly if I only had one script that sends notifications. It would become cumbersome if I needed to edit multiple scripts to change say an email address where my notifications are sent. In other words the collecting and notification logics shall be separated. To do this one can use 'PUTNOTIF' statement that shall be sent to the script STDOUT - exactly the same way like 'PUTVAL' is sent. Documentation of the 'PUTNOTIF' arguments can be found on the collect-exec module documentation page. Additionally there shall be some logic added to send notification after some time out period otherwise emails would be sent after each $COLLECTD_INTERVAL which is by default 30 seconds. Updated tmpcollect.sh script is shown below:
Part 2
Part 3
There is only one thing left to explain - how to get notified if some values go out of scope. As an example I'm going to send notification emails if CPU temperature reaches 57 degree Celsius. This could be implemented with only one additional if statement and this would work perfectly if I only had one script that sends notifications. It would become cumbersome if I needed to edit multiple scripts to change say an email address where my notifications are sent. In other words the collecting and notification logics shall be separated. To do this one can use 'PUTNOTIF' statement that shall be sent to the script STDOUT - exactly the same way like 'PUTVAL' is sent. Documentation of the 'PUTNOTIF' arguments can be found on the collect-exec module documentation page. Additionally there shall be some logic added to send notification after some time out period otherwise emails would be sent after each $COLLECTD_INTERVAL which is by default 30 seconds. Updated tmpcollect.sh script is shown below:
Labels:
bash,
collectd-exec,
OpenWRT
Monday, January 24, 2011
Friday, January 21, 2011
collectd-mod-exec Part 2
Part1
My router SBC is equipped with two temperature sensors to monitor cpu and board temperatures. Executing 'sensors' command produces the following result:
My router SBC is equipped with two temperature sensors to monitor cpu and board temperatures. Executing 'sensors' command produces the following result:
root@Alix:~# sensors lm86-i2c-0-4c Adapter: CS5536 ACB0 temp1: +36.0 C (low = +0.0 C, high = +70.0 C) (crit = +85.0 C, hyst = +75.0 C) temp2: +42.5 C (low = +0.0 C, high = +70.0 C) (crit = +85.0 C, hyst = +75.0 C)With a bit of the script-fu I'm stripping temperature values and feeding them into the database:
Labels:
bash,
collectd-exec,
OpenWRT
Thursday, January 20, 2011
collectd-mod-exec Part 1
Having some spare time I decided to write about powerful yet not well documented feature of the OpenWRT's luci-app-statistics plugin -- collectd-mod-exec module. This module allows collecting any type of data an external application could supply. In other words the module starts a user specified application which feeds collectd module with data. Principally having this module installed one could simulate all other collectd-mod-* modules.
Labels:
bash,
collectd-exec,
OpenWRT
Subscribe to:
Posts (Atom)