dummy port listener linux

Sometimes we need to test the network port and make sure that there is connectivity between servers.

In many cases, the app that might be listening on the port might not be ready yet. For such use cases, you can create a port listener on any port using netcat.

nc -l 3000

This will create a listener at the port 3000 on the server. To create who has connected to the port, use the verbose mode.

nc -lv  3000


Connection from x.x.x.x port 3000 [tcp/hbci] accepted

Create Basic Auth

You might need to generate basic authentication string when trying to use apache htaccess or for restricting web access.

The simple way to generate it is by using openssl.

echo -n username:password | openssl base64

How to make subject lines appear in maillog

Klog syslog
HSubject: $>+CheckSubject

R$*     $: $(log Subject: $1 $) $1

Make sure that the blank spaces after R$8 is a tab and not 4 spaces.

Build the macro

    m4 sendmail.mc > sendmail.cf

Restart sendmail

/etc/init.d/sendmail restart

You should now start to see the subject as a separate line in the log. Use the unique id to find the subject line

sendmail[21030]: w182kQTv021030: Subject:test123


Port check script

NC=’\033[0m’ # No Color

function checkport {
if nc -zv -w30 $1 $2 <<< ” &> /dev/null
echo “${GREEN}[O]${NC} $1:$2”
echo “${RED}[C]${NC} $1:$2”

printf “server list:”;
read server
printf “ports list[enter for default]:”
read ports_to_check

if [[ $ports_to_check = “” ]]; then
echo “using default port list”;
ports_to_check=”22 389 3306 8080″; #enter your default list of ports here
echo “$ports_to_check”;

for i in $server;do
echo “==========================================”
for j in $ports_to_check ; do
checkport $i $j
}; done

Find your tomcat version

Sometimes you might need to figure out your tomcat version from within the folder where you run tomcat from. The below command will help you get the details.

java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo

/usr/share/tomcat7$ java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo
Server version: Apache Tomcat/7.0.81
Server built: Aug 11 2017 10:21:27 UTC
Server number:
OS Name: Linux
OS Version: 3.13.0-95-generic
Architecture: amd64
JVM Version: 1.7.0_75-b13
JVM Vendor: Oracle Corporation

how to wget from a site with authentication

when you got to download from a site that ask for authentication details use the below flags to specify the user and password details


wget  –user=’yourusernamehere’ –password=’yourpasswordhere’ –auth-no-challenge  https://yoururlhere.com

ERROR 1217 (23000) at line 287: Cannot delete or update a parent row: a foreign key constraint fails

ERROR 1217 (23000) at line 287: Cannot delete or update a parent row: a foreign key constraint fails

If you got this error, it means that you are trying to restore a database sql file which got dependancy on other tables.

To override and restore anyway, add this to the top of the .sql dump file


This will make sure that the foreign key checks are disabled for the session while restoring.

How to monitor database restore progress

Use the mysql admin tool to see the rows inserted

mysqladmin -u root -p extended -r -i 10 |grep ‘Innodb_rows_inserted ‘

Also you can use the processlist command inside mysql to view the activity. This will be best if there are no other activities going on the mysql db

mysql> show processlist;