Showing posts with label Bash. Show all posts
Showing posts with label Bash. Show all posts

Tuesday, February 21, 2017

A Caveman's Bash Editor

WSO2 is in the process of improving its CI/CD pipeline in preparation for a bunch of new products(btw did you hear about our exciting new integration language? find more information here: http://ballerinalang.org/) and yours truly was given the awesome responsibility of creating a jenkins post build shell script inline with this goal. During this process I noticed a serious lack of tools for shell/bash script writers and so i wrote this simple helper script.

bash script
vim script


How to get it working,

  1. Install vim if you don’t have it in your box.
  2. Copy the vimrc file to $HOME/.vim/
  3. Move CavemansBashEditor.sh to a location of your liking and run it providing the bash script that needs to be syntax checked as a script parameter e.g. ./CavemansBashEditor.sh /home/dumiduh/myscript.sh
  4. Leave the script running and refer to it while editing your script(Refer screenshot below).




Notes,

  • The script uses ‘bash -n’ linux command and will only pick up syntax errors it picks up.
  • The vimrc file changes the vim editors behavior so that it automatically saves changes, this behavior can be a pain at times so remove the file from $HOME/.vim/ when the script is not used.
  • The script was tested on Ubuntu 14.04 with vim 2:7.4.052-1ubuntu3


Saturday, July 2, 2016

How to find more needles

If you're someone like me who needs to find needles in log haystacks then bash and grep are surely your friends. Here are two tricks I've come to use to make my work easier.

Making errors scream!

Okay so you have four or five terminal tabs going tailing different but related logs and the logs keep on pilling up. A script like the one I got below should be useful (given that you have headphone on, unless you getting weird looks from people around you). 

The script tails a log periodically and checks for the existence of a word(or phrase). If a match is made it plays an audio file(wave) to get your attention.



Usage,

sh logchecker.sh <NO_OF_LINE_TO_TAIL> <LOG_FILE> <WORD_TO_LOOK_FOR> <WAV_FILE> 

Redirect errors to a file

You have a server with debug log level enable at the root. The logs are putting on MBs instead of KBs. Grep out what you need to a separate file to make analysis more manageable.



Usage,

sh grepout.sh <LOG_FILE> <NUM_LINES_BEFORE_MATCH> <NUM_LINE_AFTER_MATCH> <WORD_TO_MATCH> 

What's in my Bag? EDC of a Tester