2019-04-10

Original tomcat.service





[billson@virtual-jenkins ~]$ sudo yum info tomcat
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.nus.edu.sg
 * extras: mirror.nus.edu.sg
 * updates: mirror.nus.edu.sg
Installed Packages
Name        : tomcat
Arch        : noarch
Version     : 7.0.76
Release     : 9.el7_6
Size        : 303 k
Repo        : installed
From repo   : updates
Summary     : Apache Servlet/JSP Engine, RI for Servlet 3.0/JSP 2.2 API
URL         : http://tomcat.apache.org/
License     : ASL 2.0
Description : Tomcat is the servlet container that is used in the official Reference
            : Implementation for the Java Servlet and JavaServer Pages technologies.
            : The Java Servlet and JavaServer Pages specifications are developed by
            : Sun under the Java Community Process.
            :
            : Tomcat is developed in an open and participatory environment and
            : released under the Apache Software License version 2.0. Tomcat is intended
            : to be a collaboration of the best-of-breed developers from around the world.



/usr/lib/systemd/system/tomcat.service


# Systemd unit file for default tomcat
#
# To create clones of this service:
# DO NOTHING, use tomcat@.service instead.

[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=simple
EnvironmentFile=/etc/tomcat/tomcat.conf
Environment="NAME="
EnvironmentFile=-/etc/sysconfig/tomcat
ExecStart=/usr/libexec/tomcat/server start
SuccessExitStatus=143
User=tomcat

[Install]
WantedBy=multi-user.target





/usr/lib/systemd/system/tomcat@.service

# Systemd unit file for tomcat instances.
#
# To create clones of this service:
# 0. systemctl enable tomcat@name.service
# 1. create catalina.base directory structure in
#    /var/lib/tomcats/name
# 2. profit.

[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=simple
EnvironmentFile=/etc/tomcat/tomcat.conf
Environment="NAME=%I"
EnvironmentFile=-/etc/sysconfig/tomcat@%I
ExecStart=/usr/libexec/tomcat/server start
ExecStop=/usr/libexec/tomcat/server stop
SuccessExitStatus=143
User=tomcat

[Install]
WantedBy=multi-user.target





2019-04-09

ps -ef grep -v multi


Google'ed by: ps -ef grep -v multi




Reference URL: https://stackoverflow.com/a/13330924/676104


Use a separated list of of processes:
#!/bin/bash
PROC="nginx mysql ..."
for p in $PROC
do
  ps cax | grep $p > /dev/null

  if [ $? -eq 0 ]; then
    echo "Process $p is running."
  else
    echo "Process $p is not running."
  fi

done
If you simply want to see if either one of them is running, then you don't need loo. Just give the list to grep:
ps cax | grep -E "Nginx|mysql|etc" > /dev/null



To exclude by using:


ps -ef | grep -vE "grep|vim |tail " | grep tomcat








2019-04-03

Access Fail2ban Database, /var/lib/fail2ban/fail2ban.sqlite3






vim ~/.sqliterc

.mode column
.headers on
.nullvalue NULL
attach "/var/lib/fail2ban/fail2ban.sqlite3" as fail2ban;





ls -lrth /var/lib/fail2ban/fail2ban.sqlite3

sudo chown :SystemAdmin /var/lib/fail2ban/fail2ban.sqlite3
sudo chmod g+r /var/lib/fail2ban/fail2ban.sqlite3

assign yourself into group: SystemAdmin


sqlite3















sqlite> .databases
seq  name             file
---  ---------------  ----------------------------------------------------------
0    main
2    fail2ban         /var/lib/fail2ban/fail2ban.sqlite3
sqlite> .tables
fail2ban.bans        fail2ban.jails
fail2ban.fail2banDb  fail2ban.logs





sqlite> SELECT jail, ip, strftime('%Y-%m-%d %H:%M:%S', timeofban, 'unixepoch' ) AS 'DateTime of ban', timeofban FROM fail2ban.bans ORDER BY timeofban DESC LIMIT 3;

jail|ip|DateTime of ban|timeofban
sshd|xxx.xx.xxx.xxx|2019-04-03 09:05:21|1554282321
sshd|xxx.xx.xxx.xxx|2019-04-03 09:04:01|1554282241
sshd|xx.xxx.xx.xx|2019-04-03 09:03:48|1554282228




Ban perform by month


sqlite> SELECT strftime('%Y-%m', timeofban, 'unixepoch' ) AS 'Date', COUNT( 1 ) FROM fail2ban.bans GROUP BY strftime('%Y-%m', timeofban, 'unixepoch' );

Date|COUNT( 1 )
2019-01|6078
2019-02|10906
2019-03|2428
2019-04|571


Ban performed by week of the year


sqlite> SELECT strftime('%W', timeofban, 'unixepoch' ) AS 'Week of Year', strftime('%Y-%m', timeofban, 'unixepoch' ) AS 'Date', COUNT( 1 ) FROM fail2ban.bans GROUP BY strftime('%Y-%m', timeofban, 'unixepoch' ), strftime('%W', timeofban, 'unixepoch' );
Week of Year  Date        COUNT( 1 )
------------  ----------  ----------
01            2019-01     1074
02            2019-01     1502
03            2019-01     2005
04            2019-01     1497
04            2019-02     1218
05            2019-02     1490
06            2019-02     3719
07            2019-02     3272
08            2019-02     1207
08            2019-03     229
09            2019-03     1258
10            2019-03     941
13            2019-04     577

Ban performed on current month of the year


2019-Apr-05_am105521
sqlite> SELECT strftime('%W', timeofban, 'unixepoch' ) AS 'Week of Year', strftime('%Y-%m-%d', timeofban, 'unixepoch' ) AS 'Date', COUNT( 1 ) FROM fail2ban.bans WHERE strftime('%Y-%m', timeofban, 'unixepoch' ) = strftime('%Y-%m', DATE('now') ) GROUP BY strftime('%Y-%m-%d', timeofban, 'unixepoch' ), strftime('%W', timeofban, 'unixepoch' );
Week of Year  Date        COUNT( 1 )
------------  ----------  ----------
13            2019-04-01  205
13            2019-04-02  290
13            2019-04-03  174
13            2019-04-04  13
13            2019-04-05  5






List of ip with count of banned.


SELECT ip, COUNT( 1 ) FROM fail2ban.bans GROUP BY ip  ORDER BY COUNT( 1 ) DESC;






List of ip with count of banned more than twice.


SELECT ip, COUNT( 1 ) FROM fail2ban.bans GROUP BY ip HAVING COUNT( 1 ) > 2 ORDER BY COUNT( 1 );



List of Top 50 ip with most count of banned.


SELECT ip, COUNT( 1 ) FROM fail2ban.bans GROUP BY ip HAVING COUNT( 1 ) > 2 ORDER BY COUNT( 1 ) DESC LIMIT 50;





Total count for distinct ip

SELECT COUNT( 1 ) FROM (SELECT DISTINCT( ip ) FROM fail2ban.bans );






.quit






















2019-04-01

Most common init systems for CentOS/others.


Reference URL: https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-1-practical-examples


PostedAugust 19, 2015



  • System V is the older init system:
    • Debian 6 and earlier
    • Ubuntu 9.04 and earlier
    • CentOS 5 and earlier
  • Upstart:
    • Ubuntu 9.10 to Ubuntu 14.10, including Ubuntu 14.04
    • CentOS 6
  • systemd is the init system for the most recent distributions featured here:
    • Debian 7 and Debian 8
    • Ubuntu 15.04 and newer
    • CentOS 7




















2019-03-26

batch script to kill skype WIndows 10


Google'ed by: batch script to kill skype


Reference URL: https://superuser.com/questions/346591/is-there-a-one-click-way-to-quit-skype-in-windows-7



in file: kill_skypes.bat



taskkill.exe /IM skypeapp.exe /T
taskkill.exe /IM skypebackgroundhost.exe /f
taskkill.exe /IM skypebridge.exe /T





double click "kill_skypes.bat" to kill skype...













Windows Command line get disk space in GB, export to a file.



Reference URL: https://superuser.com/a/924992



Debug mode to understand this script.

del diskspace.log & for /f "tokens=1-3" %a in ('WMIC LOGICALDISK GET FreeSpace^,Name^,Size ^|FINDSTR /I /V "Name"') do @echo wsh.echo "%b" ^& " Free=" ^& FormatNumber^(cdbl^(%a^)/1024/1024/1024, 2^)^& " GiB"^& " Size=" ^& FormatNumber^(cdbl^(%c^)/1024/1024/1024, 2^)^& " GiB"^& " Used=" ^& FormatNumber^(cdbl^(%c^-%a^)/1024/1024/1024, 2^)^& " GiB" > %temp%\tmp.vbs & more %temp%\tmp.vbs & @if not "%c"=="" @echo( & @cscript //nologo %temp%\tmp.vbs >> diskspace.log & more diskspace.log




Production script:

del diskspace.log & for /f "tokens=1-3" %a in ('WMIC LOGICALDISK GET FreeSpace^,Name^,Size ^|FINDSTR /I /V "Name"') do @echo wsh.echo "%b" ^& " Free=" ^& FormatNumber^(cdbl^(%a^)/1024/1024/1024, 2^)^& " GiB"^& " Size=" ^& FormatNumber^(cdbl^(%c^)/1024/1024/1024, 2^)^& " GiB"^& " Used=" ^& FormatNumber^(cdbl^(%c^-%a^)/1024/1024/1024, 2^)^& " GiB" > %temp%\tmp.vbs & @if not "%c"=="" @echo( & @cscript //nologo %temp%\tmp.vbs >> diskspace.log

more diskspace.log








2019-03-21

javax.mail.MessagingException: Could not convert socket to TLS;


https://stackoverflow.com/questions/16115453/javamail-could-not-convert-socket-to-tls-gmail

javax.mail.MessagingException: Could not convert socket to TLS;

Solved by: props.put("mail.smtp.ssl.trust", "smtp.gmail.com");


openjdk.java.net vs jdk.java.net



edited 6 months ago from 2019-Mar-21_pm034301


Note that while both openjdk.java.net (the OpenJDK project) and jdk.java.net (OpenJDK builds by Oracle) are run by Oracle, jdk.java.net is not an OpenJDK website.











OpenJDK vs AdoptOpenJDK


Updates@2019-Apr-01_pm040305:

I'm using OpenJDK8U-jdk_x64_linux_hotspot_8u202b08
https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u202-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz

from: https://adoptopenjdk.net/releases.html?variant=openjdk8&jvmVariant=hotspot#x64_linux



Seems previous finding

https://billson.blogspot.com/2019/03/openjdk-variants-vs-each-other-and-vs.html


  1. OracleJDK
  2. OpenJDK
    1. from Oracle
    2. from other providers




jdk_ri-8u40-b25-windows-i586-10_feb_2015>bin\java.exe -version
openjdk version "1.8.0_40"
OpenJDK Runtime Environment (build 1.8.0_40-b25)
OpenJDK Client VM (build 25.40-b25, mixed mode)

OpenJDK8U-jre_x86-32_windows_hotspot_8u202b08\bin\java.exe -version
openjdk version "1.8.0_202"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_202-b08)
OpenJDK Server VM (AdoptOpenJDK)(build 25.202-b08, mixed mode)




Reference from stackoverflow
Difference between OpenJDK and AdoptOpenJDK
https://stackoverflow.com/questions/52431764/difference-between-openjdk-and-adoptopenjdk


In short:
  • OpenJDK has multiple meanings and can be referred as:
    • free and open source implementation of the Java Platform, Standard Edition (Java SE)
    • open source repository - the Java source code aka OpenJDK project
    • prebuilt OpenJDK binaries provided by Oracle
  • AdoptOpenJDK prebuilt OpenJDK binaries provided by community



    Explanation:
    Prebuilt OpenJDK (or distribution) - binaries, built from http://hg.openjdk.java.net/, provided in a zip or installer, offered for various platforms, with a possible support contract.
    OpenJDK, the source repository (also called OpenJDK project) - is a Mercurial-based open source repository, hosted at [http://hg.openjdk.java.net]. The Java source code. The vast majority of Java features (from the VM and the core libraries to the compiler) are based solely on this source repository. Oracle have an alternate fork of this.
    OpenJDK, the distribution (see the list of providers below) - is free as in beer and kind of free as in speech, but, you do not get to call Oracle if you have problems with it. There is no support contract. Furthermore, Oracle will only release updates to any OpenJDK (the distribution) version if that release is the most recent Java release (including LTS). The day oracle releases OpenJDK (the distribution) version 12.0, even if there's a security issue with OpenJDK (the distribution) version 11.0, Oracle shall not release an update for 11.0. Maintained solely by Oracle.
    AdoptOpenJDK, the distribution - very similar to Oracle's OpenJDK distribution (in that it is free, and it is a build produced by compiling the sources from the OpenJDK source repository). AdoptOpenJDK as an entity will not be backporting patches, i.e. there won't be an AdoptOpenJDK 'fork/version' that is materially different from upstream (except for some build script patches for things like Win32 support). Meaning, if members of the community (Oracle or others, but not AdoptOpenJDK as an entity) backport security fixes to updates of OpenJDK LTS versions, then AdoptOpenJDK will provide builds for those. Maintained by OpenJDK community.
    There's also OracleJDK - another distribution, starting with JDK12 there will be no free version of this. Oracle's JDK distribution offering intended for commercial support. You pay for this, but then you do get to rely on Oracle for support. Unlike Oracle's OpenJDK offering, the OracleJDK offering does come with longer support for LTS versions. As a developer you can get a free license for personal/development use only of this particular JDK, but that's mostly a red herring, as 'just the binary' is basically the same as the OpenJDK binary. I guess it means you can download security-patched versions of LTS JDKs from Oracle's websites as long as you promise not to use them commercially.
    Note. It maybe best to call the OpenJDK builds by Oracle, the "Oracle OpenJDK builds".
    Donald Smith, Java product manager at Oracle writes:
    Ideally, we would simply refer to all Oracle JDK builds as the "Oracle JDK," either under the GPL or the commercial license depending on your situation. However, for historical reasons while the small remaining differences exist, we will refer to them separately as Oracle’s OpenJDK builds, and the Oracle JDK.

    OpenJDK Providers and Comparison

    ---------------------------------------------------------------------------
    |     Provider      | Free Builds | Free Binary   | Extended | Commercial |
    |                   | from Source | Distributions | Updates* | Support    |  
    |-------------------------------------------------------------------------|               
    | AdoptOpenJDK      |    Yes      |    Yes        |   Yes    |   No       |
    | Azul              |    No       |    Yes        |   Yes    |   Yes      |
    | IBM               |    No       |    No         |   Yes    |   Yes      |
    | Mercurial         |    Yes      |    Yes        |   No     |   No       |
    | Oracle            |    No       |    Yes        |   No**   |   Yes      |
    | RedHat            |    Yes      |    Yes        |   Yes    |   Yes      |
    | SapMachine        |    Yes      |    Yes        |   Yes    |   Yes      |
    | Amazon – Corretto |    Yes      |    Yes        |   Yes    |   No       |
    ---------------------------------------------------------------------------
    
    * Extended Updates - Public Updates beyond the 6-month release lifecycle
    ** Oracle provides extended updates (and support) to paying customers, i.e. Oracle JDK only

    Additional information
    Time to look beyond Oracle's JDK by Stephen Colebourne
    Java Is Still Free by Java Champions community (published on September 17, 2018)
    Java is Still Free 2.0.0 by Java Champions community (published on March 3, 2019)






2019-03-19

WinSCP configure hostkey in winscp script


What's WinSCP hostkey


Before OpenSSH 6.8
 ssh-keygen -lf <(ssh-keyscan localhost 2>/dev/null)



Since OpenSSH 6.8, you have to add the -E md5 switch to get the format needed for WinSCP.

ssh-keygen -E md5 -lf <(ssh-keyscan localhost 2>/dev/null)


[billson@169 ~]$ ssh-keygen -E md5 -lf <(ssh-keyscan localhost 2>/dev/null)
2048 MD5:aa:bb:cc:xx:xx:xx:xx:43:79:ae:90:ca:83:d3:xx:ef localhost (RSA)
256 MD5:xx:81:xx:7a:xx:49:68:87:xx:a3:54:xx:61:b3:xx:15 localhost (ECDSA)
256 MD5:xx:69:29:4a:xx:f0:8f:74:xx:5d:1b:86:aa:xx:d7:1b localhost (ED25519)



USING (RSA)
GET CONTENT BETTWEN [MD5:]*********************[localhost (RSA)] without space
SUPPOSE also using 2048


Replace
open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx..."
to:
open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 aa:bb:cc:xx:xx:xx:xx:43:79:ae:90:ca:83:d3:xx:ef"




2019-03-18

tar gzip with or without GZIP=-9



target folder name: 2019_02
target folder size: 1.3G




tar -cvzf 2019_02.default.tgz 2019_02
Compressed: 318M 2019_02.default.tgz



GZIP=-9 tar -cvzf 2019_02.GZIP=-9.tgz 2019_02
Compressed: 310M 2019_02.GZIP=-9.tgz



linux find files older than 365 days exclude multiple paths


Navigate to target folder, search sub folders and sort files details older than 365 days with folder exclusion config below:

find . -type d \( -path "./Programs/jdk1.7.xxx" -o -path "./Programs/apache-tomcat-7.0.xxx" -o -path "./Programs/mysql-xxx" \) -prune -o -mtime +365 | sort

Similar as above, but ls -lrth

find . -type d \( -path "./Programs/jdk1.7.xxx" -o -path "./Programs/apache-tomcat-7.0.xxx" -o -path "./Programs/mysql-xxx" \) -prune -o -mtime +365 -exec ls -lrth {} \;




Google'ed: linux find exclude directory






Reference URL: https://stackoverflow.com/questions/4210042/how-to-exclude-a-directory-in-find-command






Use the prune switch, for example if you want to exclude the misc directory just add a -path ./misc -prune -o to your find command:
find . -path ./misc -prune -o -name '*.txt' -print
Here is an example with multiple directories:
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print
Here we exclude dir1, dir2 and dir3, since in find expressions it is an action, that acts on the criteria -path dir1 -o -path dir2 -o -path dir3 (if dir1 or dir2 or dir3), ANDed with type -d. Further action is -o print, just print.














2019-03-15

OpenJDK variants vs each other and vs Oracle JDK





Reference URL: https://medium.com/@javachampions/java-is-still-free-c02aef8c9e04

OpenJDK variants vs each other and vs Oracle JDK





Seems we have:

  1. OracleJDK
  2. OpenJDK
    1. from Oracle
    2. from other providers



Reference:
Q. Differences between OpenJDK vs Oracle’s OpenJDK builds vs Oracle JDK?
We’ll just talk about Java 11+ LTS releases here. Oracle JDK and Oracle OpenJDK builds are identical, but are licensed in different ways (commercial and GPLv2+CE respectively).
Oracle JDK / Oracle OpenJDK builds and OpenJDK builds from other providers will be built from the same source for the first six months of updates and should be interchangeable for that period. After six months Oracle JDK / Oracle OpenJDK builds will be built from Oracle’s own fork. Other OpenJDK providers will continue to create binaries from the OpenJDK updates project. Oracle JDK / Oracle OpenJDK and OpenJDK builds from the other providers may therefore differ in small ways. Binaries from various parties may, of course, vary over time.

Q. Differences between OpenJDK from (non-Oracle) provider A vs provider B?
We’ll just talk about LTS releases here. As has been the case with the Java SE 6 and Java SE 7 updates projects, various providers work together upstream in the OpenJDK community, which provides the common repositories, mailing lists, and other infra to share the work. This means the difference between OpenJDK-based binaries are mostly non-core features, like extended monitoring and diagnostic support. Although there may be small differences in the final binaries (perhaps a provider-specific tool etc) they will all at least have the same security and stability baseline as has been true for many years.









linux sort data size


Google'ed by: linux sort data size



https://serverfault.com/questions/62411/how-can-i-sort-du-h-output-by-size




Reference script: du | sort -nr | cut -f2- | xargs du -hs





Script that I used:

du --max-depth=1 / | grep -v '\.' | sort -nr | cut -f2- | xargs du -hs


Google Referrals