I use CURL for debugging my REST endpoints every now and then if I don’t want to use Postman or DHC clients. I usually like to copy paste results / statistics from command line into emails to my colleagues. This gives them a plain jane command which they can use to test themselves as well as compare their results with mine. The following article has some good pointers on how to use CURL and some very practical examples have been provided.
I recently got into a situation where I had to debug around 10 servers all of which were suffering from memory issues. My java applications were slowing down after a day or so. Although its is difficult to diagnose this kind of issues which span across multiple VMs (welcome to Micro Services!) but with some little bit of scripting it is possible to see in real time the actual numbers if you manage to use tmux to multiplex multiple shell sessions stacked together. I hacked up the following command to display hostname, running war files as well as the memory statistics refreshed every 1 second on screen.
watch -d -n 1 "hostname | tr '\r\n' ' ' && printf \" \" && jps -l | grep .war | tr '\r\n' ' ' && echo "" && free -h"
I found a good link which lists good usages of the Linux command “du”.
This command allows me to see the usage in a ascending sort which is really helpful.
Tested on Linux.
du -h / | sort -h
Tested on Mac OS.
du -hs * | gsort -h
In case you don’t have gsort install coreutils.
brew install coreutils
This variation allows me to see any line which has the text “G” in it which basically allows me to see folders using space in GBs. Agreed it might give some folder names as well with “G” in it but I can bear with it.
Tested on Linux.
du -h /the/path | sort -h | grep "G"
Tested on Mac OS.
du -h /the/path | gsort -h | grep "G"
I needed to make SSH connection into a VM box setup inside VirtualBox which by default uses NAT. To enable this I had to setup port forwarding. This article proved useful.
I used this link to fix the error of sudo command not found on fresh install of Debian 8.
I used this link to successfully setup a Open SSH server on a Debian 8 VM.
I needed to write a small shell script which would allow me to make some decision based on user choices. I needed the user to specify Yes, No or Cancel for an operation. The following piece of hack does the job well.
# define constants
declare -r TRUE=0
declare -r FALSE=1
# Prompt user, and read command line argument
read -p "$str " answer
# Handle the input we were given
case $answer in
[yY]* ) return $TRUE;;
[nN]* ) return $FALSE;;
[cC]* ) exit;;
* ) echo "Y - Yes, N - No, C - Cancel. Please choose valid option.";;
if user_choice "Execute Job 1? "; then
echo "Executing Job 1.."
if user_choice "Execute Job 2? "; then
echo "Executing Job 2.."
The following links were referred to achieve this little script:
The vi editor in Linux does line wrapping by default. To turn this off for some files with huge lines I use the following command from vi command prompt:
To disable wrap.
To enable wrap.
I use this ultimate cheat sheet for vi command on Linux whenever in doubt:
I have a utility which compiles my UI code and minifies them. It works pretty well and doesn’t requires much supervision. Trouble starts if the code compilation fails and it gets ignored in the huge log file which is generated by this utility. I use the following approach to filter out errors and yet preserving the output of the utility program for any diagnostic in case of any error.
./my_utility.sh | tee output.txt | grep error
Basically what happens is that “my_utility.sh” generates a lot of output which is piped into the “tee” command which in turn dumps it into a text file named “output.txt” and then the same output is again piped into the “grep” command which looks for any error text in the output. If the error is found it is outputted on the console.
So the end result is that in 99% cases I don’t see any output from the utility as I don’t want to see debug output. However the moment an error happens it gets flagged on console and I have the “output.txt” file to audit what went wrong and the root cause of the error.