On Java, Python, Groovy, Grails, Spring, Node.js, Linux, Arduino, ARM, Embedded Devices & Web

Posts Tagged ‘Linux’

How to Add Route in Linux?

Posted by Venkatt Guhesan on May 11, 2017

Examples of Route Command and it’s usage.

Source: 7 Linux Route Command Examples (How to Add Route in Linux)

To learn the fundamentals of Routing, please visit the link below:

Fundamentals of Routing



Posted in Linux | Tagged: , , | Leave a Comment »

How To Record Everything You Do In Terminal – OSTechNix

Posted by Venkatt Guhesan on March 13, 2017


script -a my_history

mkdir test

cd test

touch hello_world.txt

echo 'Hello World' > ./hello_world.txt

# This closes the "script -a my_history" file

Source: How To Record Everything You Do In Terminal – OSTechNix

Posted in Bash, CentOS 6.X, CentOS7, Linux, Scripting | Tagged: , , , , , | Leave a Comment »

Developing email applications on Windows, targeted for Linux environment – email, mailx, sendmail

Posted by Venkatt Guhesan on December 11, 2016

linux_centos_logoIf you’re developing on a Windows platform for an application targeted for Linux or Unix that deals with email, then this article will be useful.

Let us begin by  understand the problem.


If you are a Java/Spring developer, (developing in Java is platform independent – runs on any platform where a JVM is available) then you have two options in front of you for sending emails from a Java application:

Option #1: JavaMail API

Option #2: Linux sendmail or mailx invoked via Runtime.getRuntime().exec(invoke – linux – mail – command) [example here]

If you are a PHP or Ruby or Bash or Python developer, you can do the same using a native library available within the language or invoke a native Linux execute-command to invoke either sendmail or mailx.

What happens if you are developing a hybrid library that needs to send email both from Java and Python. Then most likely you want to leverage a common library accessible to all the various libraries. In this case, you’re going to depend on either sendmail or mailx.   Now let us throw in a additional problem into this mix. Suppose you are developing on a Windows platform but the end application is targeted to run on Linux. This now creates a new additional problem. Sendmail or Mailx do not exist for Windows. Well, this article provides a way to develop on Windows by invoking execute mailx calls from your native code to the underlying emulation of Linux on Windows.

Now that we have established the problem, let us walk through a solution.

Please note that this is not the only solution but a potential solution. If you know of other mechanisms, feel free to send me a link and I’ll add them in.


Step-1: Make sure that you have Cygwin installed (with email tool selected additionally) on your Windows computer.

# Download  setup-x86_64.exe from
# and run it.

# When you run the setup, please additionally select "email" tool additionally. It is not added by default.

Once Cygwin is installed, most people traditionally use all the Cygwin tools from within a Cygwin Command-Prompt. The executables are located under “\bin\**” directory. Which means that if you run a “ls” in a DOS command-prompt, it will error saying “command not found”. There is a undocumented\not so known secret to emulating Linux commands natively in Windows. This is where your true Linux power comes in under native Windows.

Step-2: Add Cygwin\bin path natively to Windows PATH.

# In my computer, I have Cygwin installed at the following path: c:\cygwin64\

To add "c:\cygwin64\bin" the system path, perform these steps:

1. Start the System Control Panel applet (Start - Settings - Control Panel - System).
2. Select the Advanced tab.
3. Click the Environment Variables button.
4. Under System Variables, select Path, then click Edit.
5. Add c:\cygwin64\bin to the path.

Once Step-2 is completed. If you start a new DOS command-prompt and run a “ls” command, you should see the directory listing (same as a ‘dir’ command under Windows).

Step-3: The send email application uses “c:\cygwin64\etc\email\email.conf” for SMTP and other email properties.

# Edit c:\cygwin64\etc\email\email.conf and add your SMTP details (domain/server name, user-id, password)
# For this example, I have setup a *special* GMail Email account specially to test [Don't use your private GMail] so I will use the user-id and password for that Gmail account.

SMTP_PORT = '587'
USE_TLS = 'true'
MY_NAME  = 'Venkatt Guhesan'

Step-4: Let’s test this under a DOS command-prompt.

# Open a DOS Command-Prompt and run the following:

echo "Test from Cygwin in Windows under DOS command-prompt" | email -s "Testing Email from Windows DOS" 

# Within minutes, you should see an email in the Gmail inbox as expected.

# If you are not seeing it, then you can use the example below where you can pass in the SMTP arguments for validation. Maybe you typed in the password for the Gmail account incorrectly or you entered one of the parameters incorrectly in the c:\cygwin64\etc\email\email.conf file.

echo "Test from Cygwin in Windows under DOS command-prompt" | email -s "Tetsing Email" -r -p 587 -m login -u -i YOUR_GMAIL_PASSWORD_GOES_HERE -tls


Once you have confirmed a successful email then the next step is to create a mailx application.

Step-5: Create a mailx.exe (mailx) within Cygwin’s bin directory.

For emulating mailx from Cygwin’s email.exe, you’re in luck. The format for mailx is identical to the email.exe’s arguments. All you are missing is mailx.exe. So simply copy email.exe under Cygwin’s bin directory to mailx.exe under the same Cygwin’s bin directory. And you’re all set!

# simply copy email.exe under Cygwin's bin directory to mailx.exe under the same Cygwin's bin directory

cd c:\cygwin64\bin
cp email.exe mailx.exe

# Now just like you running email (without the .exe suffix) you can run mailx (without the .exe suffix)

Step-6: Test sending an email using mailx

echo "Test from Cygwin-mailx in Windows under DOS command-prompt" | mailx -s "Testing Email from Windows DOS" 


As a last step, now within your Java application, test Runtime.getRuntime().exec(“mailx command”);

Runtime.getRuntime().exec("echo 'Test from Cygwin-mailx in Windows under DOS command-prompt' | mailx -s 'Testing Email from Windows DOS'");

Now your Java application as well as any Python, Bash, Linux shell applications and/or scripts are now leveraging the common “mailx” and your development is now consistently the same using one common mailx library.


Today’s inspirational quote:
  • We must all either wear out or rust out, every one of us. My choice is to wear out.
– Theodore Roosevelt, an American statesman, author, explorer, soldier, naturalist, and reformer who served as the 26th President of the United States from 1901 to 1909.

Posted in Bash, CentOS 6.X, CentOS7, Grails, Groovy, Java, Linux, Spring, Windows | Tagged: , , , , , , | Leave a Comment »

CentOS7 missing Net-Tools Package and why you should not install it moving forward

Posted by Venkatt Guhesan on December 9, 2016

centos_logoIn CentOS 7, a lot of the command-line utilities for configuring and troubleshooting network properties like arp, ifconfig, iptunnel, iwconfig, nameif, netstat, route – are no longer there in the new CentOS 7 version. While still included in many Linux Distributions, (and you may be tempted to run – ‘yum install net-tools’ – to get them back into your Linux footprint). But they are considered deprecated and therefore should be phased out in favor of more modern replacements. If you visit the link to net-tools project [and here] you will see that the last build of the tar.bz2 file was sometime back in October 14th, 2011.

This opens up some possibility for security vulnerabilities that may not get adequately patched. When you are developing applications for the Linux Platforms or running server configurations on Linux out in the cloud, you should move away from leveraging the net-tools as part of your portfolio. You will also notice that the modern tools leverage multi-core processing & parallelization (in some cases) to speed things up and you may notice a slight performance improvement in some of the commands. If your script is iterating through a collection running a certain net-tools command, your script will see a noticeable difference in time.

The CentOS 7 team has decided to move to iproute2 but some of the commands are not as trivial and requires a bit of familiarization before you can readily use it.

For example, the ss command that aids in determining if a port is open or used when compared with netstat can yield faster results because it directly queries the kernel using Netlink and the classic sockets API rather than going through the proc-fs file system (/proc/net/tcp) to acquire the system network information. So this approach makes the results come back faster. You can see the fun and gory code details here.

Here is a quick table that summarizes the older net-tools command and it’s new IPRoute2 equivalent:

Net-Tool *old* Command IPRoute2 *new* Command Purpose/Notes
arp ip neigh (ip neighbor) Neighbors
ifconfig ip addr, ip link, ip -s Address and Link Configuration
route ip r, ip route Routing Tables
iptunnel ip tunnel Tunnels (but simplified)
nameif ip link, ifrename Rename Network Interfaces (very useful since CentOS 7 names tdem like enp0s3 instead of tdaditional etd0)
netstat ss, ip route (for netstat -r), ip -s link (for netstat -i), ip maddr (for netstat -g) Display networking statistics (good for monitoring your net stack)
ipmaddr ip maddr For multicasting – very useful for all tde micro-services, auto-discovery protocols etc


Today’s inspirational quote:
  • The impediment to action advances action. What stands in the way becomes the way.
  • Here is one way to think of hardship: I am a failure. I have met the end. Finito. I’m stupid. or
    Here is another way to think of the same hardship: A chance to learn about endurance, patience, resilience, struggle. An opportunity to prove. An opportunity to learn from the mistakes.When faced with an obstacle, think of it as the way forward. Until you acknowledge it and accept it as defeat within your confines of your mind, it remains as an opportunity and a way forward!

Posted in CentOS7, Linux | Tagged: , , , , , , , , , , | Leave a Comment »

CentOS 6.8 & 7 – Change Timezone

Posted by Venkatt Guhesan on November 6, 2016


Here is a cheat sheet on changing the timezone in a linux system (CentOS 6.8 or 7):

# Remove the current timezone file
rm /etc/localtime

# Create a symbolic link to the new timezone you want
# ls -la /usr/share/zoneinfo/
# ls -la /usr/share/zoneinfo/US/

# For GMT
ln -s /usr/share/zoneinfo/GMT /etc/localtime
# For EST
ln -s /usr/share/zoneinfo/EST /etc/localtime
# For UTC
ln -s /usr/share/zoneinfo/UTC /etc/localtime
# For GMT
ln -s /usr/share/zoneinfo/GMT /etc/localtime
# For New York (Eastern)
ln -s /usr/share/zoneinfo/US/Eastern /etc/localtime
# For Central
ln -s /usr/share/zoneinfo/US/Central /etc/localtime
# For Mountain time
ln -s /usr/share/zoneinfo/US/Mountain /etc/localtime
# For Pacific time
ln -s /usr/share/zoneinfo/US/Pacific /etc/localtime

# Set Date and Time (as needed)
date 072522172010
hwclock --systohc

# If you're using NTPD Service
# CentOS 6.8
service ntpd stop && service ntpd start
# In CentOS 7 
systemctl stop ntpd && systemctl start ntpd

You may also be interested in NTP Service blog article here.

Today’s inspirational quote:
  • Men (people) are disturbed not by events but by their opinion about events.
  • Wealth consists not in having great possessions, but in having few wants.

Posted in CentOS 6.X, CentOS7, Linux | Tagged: , , , , , | Leave a Comment »

Node.js, Python, C/C++, Ruby, PHP development from a tiny Linux embedded for about $10

Posted by Venkatt Guhesan on October 4, 2016


Came across this tiny IoT embedded micro-controller/computer that runs BusyBox or FreeBSD Linux and can run code written in Node.js, Python, C/C++, Ruby and PHP all at a cost of $5 to $10 with WiFi, 2G/3G, Bluetooth, GPS add-ons for your cloud services. It also has enough GPIO pins to interface with external world and not to mention the I2C and I2S interfaces for talking to other devices and peripherals as well as interfacing for sounds (I2S).

Omega2 from

For that price, it might be worth considering it!

Posted in Embedded Systems, Linux | Tagged: , , , , , , , | Leave a Comment »

Two useful links comparing CentOS 6.X’s – SysV-Init vs CentOS 7.X – SystemD – init systems

Posted by Venkatt Guhesan on July 19, 2016

In CentOS 6.8, the init system that brings up all the services (link autoexec files in Windows) was called SysV- Init. This has been the foundation for ages as long I’ve been using CentOS. But in the latest release of CentOS (CentOS 7+) the init engine has been moved to a more favorable engine labeled SystemD. SystemD is the init engine behind Ubuntu, Fedora, Red Hat and CentOS. So the standardization is good for the Linux community but moving from CentOS 6.8 to CentOS 7 is not a trivial task (especially when it comes to RPMs that working on the SysV-Init paradigm).

Here are two links that outlines the differences:




Posted in CentOS 6.X, CentOS7, Linux | Tagged: , , , , , , | Leave a Comment »

merging bash ssh session history

Posted by Venkatt Guhesan on March 24, 2016

linuxlogoYou may have observed once in a while that when you SSH onto a server and you try to look up a command you ran earlier (maybe the previous day) in the “history” output but you do not see it. This is because of how a SSH session works! Each time you ssh into a server, it leverages a set of TTY screens to maintain an individual history for that session. So for example, the first ssh login (for the same userid) may get TTY session #1 and the second ssh login may get TTY session #2 and the server maintains individual session history. So unless, you end up on the same TTY ID the next day (or the next time you login), the commands you ran on the previous day will not appear on the “history” output.

Linux & Bash (I said ‘bash’ for a reasons mentioned below) provides a very simple solution to merge your history so that all commands you (and many users logging in under the same ID like ‘root’) in all TTY sessions gets consolidated under one history. This is *rarely* known to Linux users but can come in very handy during investigations.

This is a great command to know especially when you’re trying to investigate how files went missing on the server. Most likely, a user with ‘root’ permissions ran a “rm (remove) * -Rf” command not realizing they were removing files under a different directory such as /var or /usr/bin.

# Run the following to merge
history -a
# Now if you type history, you will now see all of the commands you ran merged under one space

WARNING: The command may or may not work in your environment. To learn why, read on…

Please note that the “history” command is not a “Linux” command but rather a command offered by the respective shell such as “BASH”. And that is why when you run “man history”, you get all the commands provided by BASH. In most cases, BASH is the default preferred shell so when you SSH into a server you may end up in a BASH shell. But there are many others such as KORN, ASH, BSH, KSH, ZSH and so on. Each shell tries to overcome some kind of limitation. So depending upon the shell you’re using some of the commands such as “history -a” may or may not work accurately. Consult your favorite shells’ man pages to determine how to merge the history.


Today, considering a comment made by my daughter, I thought I’d end all my blogs with a famous quote that inspires me in hopes that others that read my blog daily can also find inspiration and solace in their daily lives.

Now for the quote that has moved me today:

History will judge us by the difference we make in the everyday lives of children.
Nelson Mandela
[Freedom fighter, Anti-apartheid Revolutionary, President of South Africa]


Posted in CentOS7, Linux | Tagged: , , | Leave a Comment »

CentOS 7 – How to open ports in firewalld?

Posted by Venkatt Guhesan on March 23, 2016

centos_logoPrior to CentOS 7, “iptables” and “shorewall” were the two options avaiable. Since CentOS-7, the default firewall tool is “firewalld”.

Here is a short-guide on how to open two ports in the firewalld application:

firewall-cmd --get-active-zones
# Lets open Jetty Web Server port
firewall-cmd --zone=public --add-port=8080/tcp --permanent
# Lets open some other port 4242 for TCP
firewall-cmd --zone=public --add-port=4242/tcp --permanent
# Commit changes
firewall-cmd --reload
firewall-cmd --list-all


Posted in CentOS7, Linux, Uncategorized | Tagged: , , , , | Leave a Comment »

Cubieboard2 with ARM AllWinner Processor – A20 finally arrived

Posted by Venkatt Guhesan on November 3, 2013

Cubieboard2 with ARM AllWinner Processor – A20 finally arrived. Pretty excited about building my ARM Linux embedded system.


Learn more about Cubieboard here

Posted in CubieBoard2 & CubieTruck, Embedded Systems, Linux, Technology | Tagged: , , | Leave a Comment »