Wednesday, July 31, 2019

Deploy WAR File Into Tomcat Server of VirtualBox

Installing Tomcat 7

Step 1: Create the Tomcat Folder
Logged in as root, within the opt folder make a directory called tomcat and cdinto that folder after completion.
mkdir /opt/tomcat
cd /opt/tomcat
 Step 2: Install Tomcat Through Wget
Click this link to the Apache Tomcat 7 Download site. Place your cursor under7.0.90 Binary Distributions, right click on the tar.gz file and select Copy Link Address (as shown in the picture below).  At the time of this article Tomcat 7 is the newest version but feel free to pick whatever version is more up-to-date.
Next, from your server, use wget command to download the tar to  the tomcat folder from the URL you copied in the previous step:
wget http://www.trieuvan.com/apache/tomcat/tomcat-7/v7.0.90/bin/apache-tomcat-7.0.90.tar.gz
After the download completes, decompress the file in your Tomcat folder:
tar xvzf apache-tomcat-7.0.90.tar.gz
You will end up with a file called apache-tomcat-7.0.90.
Step 3: Install Java
Before you can use Tomcat, you’ll have to install the Java Development Kit (JDK). Beforehand, check to see if Java is installed:
java -version
If that command returns the following message then Java has yet to be installed:
The program 'java' can be found in the following packages:
To install Java, simply run the following command (and at the prompt enter Y to continue:
apt-get install default-jdk

Step 4: Configure .bashrc file
Set the environment variables in .bashrc with the following command:
vim ~/.bashrc
Add this information to the end of the file:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
export CATALINA_HOME=/opt/tomcat/apache-tomcat-7.0.90
Save your edits and exit from the .bashrc file, then run the following command to register the changes:
. ~/.bashrc

Step 5: Test Run
Tomcat and Java should now be installed and configured on your server. To activate Tomcat, run the following script:
$CATALINA_HOME/bin/startup.sh
You should get a result similar to:
Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-7-openjdk-amd64/
Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.

To verify that Tomcat is working by visiting the IP address of your server:8080 in a web browser. For example http://127.0.0.1:8080.
Tomcat 7.0.90 Test Page

To stop tomcat:
$CATALINA_HOME/bin/shutdown.sh

Share WAR Folders between Host and Guest OS in VirtualBox

You can do this by going to Devices again and clicking on Shared Folders – Shared Folders Settings.
Now click on the Add New Shared Folder button on the right.
share files virtualbox
In the Folder Path box, click the down arrow and then click Other. Browse to the folder on the host OS that you would like to share with the guest OS. In the Folder Name box, give your share a name. You can choose to make it read-only, auto-mount the folder after restarts, and make the shared folder permanent.
Click OK and the new shared folder will show up under Machine Folders if you chose to make it Permanent, otherwise it will show under Transient Folders.
share folders virtualbox
Now click OK to close the Shared Folders dialog. You have to do one more thing in order to be able to actually access the folder on the host OS. Depending on whether the guest OS is running Windows or Linux (Ubuntu, etc), the method is different.
To mount a shared folder in a Linux Guest OS such as Ubuntu, type in the following command in terminal:

mount -t vboxsf [-o OPTIONS] sharename mountpoint

Replace sharename with the name of the share and mountpoint with the path where you want the share to be mounted (i.e. /mnt/share, /media/shared).
NOTE: if you get any fs (file system) error. then execute below commands

sudo apt-get install virtualbox-guest-utils
If problem remains then install corresponding file system support as like as:
sudo apt install nfs-commonsudo apt install cifs-utils

Deploy WAR by Copy

Open terminal as a root user


sudo su
Copy WAR file to inside of tomcat webapps folder
cp /mnt/shared/project.war /opt/tomcat/apache-tomcat-7.0.90/webapps/
Then start tomcat server if required. If you need to see the log of your project:
tail -f /opt/tomcat/apache-tomcat-7.0.90/logs/project.log

Monday, May 22, 2017

Arduino Yun Command

CLI

If you are using Windows, you must install a terminal emulator, PuTTY.
  1. Download and install it by default settings
  2. Run the program
  3. Then give the IP address of Arduino
  4. A command prompt will appear
  5. Give value root for login as 
  6. If you don't change the password then give default password - aarduino

SD Card

  1. Format the SD card as FAT32 file system
  2. Plug in with Arduino
  3. For creating mount point
    • mkdir -p /mnt/sda
    • mount  /dev/sda /mnt/sda
  4. For accessing the SD card
    • cd /mnt/sda
  5. To see all file in SD card
    • ls -all
If the file system of SD card would become read only:
mount -o remount,rw /mnt/sda

USB Webcam

Configure Webcam

Check if USB camera is detected:
dmesg | tail -n3
Run following command after opening CLI. At first you need to update opkg.
opkg update
Install kmod-video-uvc
opkg install kmod-video-uvc
Sometimes kmod-video-uvc does not install for it's dependencies. Then you need to run following command to full fill it's dependencies before installing it.
opkg install usbutils
opkg install kmod-usb-core kmod-usb2 kmod-video-core
opkg install kmod-video-uvc
Run following command to complete the process
opkg install python-openssl
opkg install fswebcam
opkg install mjpg-streamer

Test Webcam

Verify if your USB webcam is detected as video device: 
ls /dev/video*
To capture a picture and stored it to SD card memory:
cd /mnt/sda
fswebcam test.png
Image will flicker sometime due to camera resolution. You have to specify resolution by -r:
fswebcam test.png -r 280x175
You can skip frame by -s:
fswebcam test.png -r 280x175 -S 2

Start Video Streaming

Check if mjpg-streamer is running on 8080 
netstat -an | grep 8080
ps | grep mjpg_streamer
If it is not running yet, you can run it manually by a simple command
mjpg_streamer -i "input_uvc.so" -o "output_http.so"
Sometimes this will show error for mismatching with camera resolution. For that situation you need to specify the resolution.
mjpg_streamer -i "input_uvc.so -y -n -f 30 -r 280x175" -o "output_http.so -p 8080 -n -w /www/webcam"
After that you will see the output in following URL.
http://192.168.xxx.xxx:8080/?action=snapshot
http://192.168.xxx.xxx:8080/?action=stream
http://192.168.xxx.xxx:8080/stream.html
Use following command to enable auto start of the service.
/etc/init.d/mjpg-streamer enable 
Use following command to manually stop the service.
killall mjpg_streamer
Use ps command to verify if the process has been run:
ps | grep mjpg 
Note 1: 192.168.xxx.xxx is an IP address of Arduino Yun.
Note 2: Video will flicker sometimes due to camera resolution.  You need to specify it by camera resolution.

Video Streaming on Youtube

  1. Download Wirecast
  2. Install and open Wirecast
  3. Click "+" on any layer (bottom of the window)
  4. Click on Web Display...
  5. Fillup field
    • Address: http://192.168.xxx.xxx:8080/?action=stream
    • Width: your_desired_width
    • Height: your_desired_height
  6. Select any shot of any layer by clicking it
  7. Then press "->" button to stream it
  8. Menu bar => Output => Output Settings [shortcut key: ctrl + y]
  9. Select YouTube from Destination dropdown
  10. Authenticate yourself
  11. Start broadcasting by pressing Stream button (top of the window)


Recording Video from Streaming URL

At first you need ffmpeg library:
opkg update
opkg install ffmpeg
Then run following command to record video for 5 seconds:
ffmpeg -f mjpeg -r 5 -i "http://192.168.xxx.xxx:8080/?action=stream" -t 5 video.avi
You can also capture image via ffmpeg:
ffmpeg -f video4linux2 -i "http://192.168.xxx.xxx:8080/?action=stream" -vframes 1 test_ffmpeg.jpeg
or
ffmpeg -f video4linux2 -i /dev/video0 -vframes 1 test_ffmpeg.jpeg
Note: Make confirm that server is running before capture image or record video.

Thanks to

Basic Linux Command

# show file/folder attribute
$ ls -l

# change file attribute
# 777 => 111,111,111 => rwx,rwx,rwx
# 531 => 101,011,001 => r-x,-wx,--x
$ chmod 777 file_or_folder_name


# see recent mounted drives
$ df
# human readable format
$ df -h


# mount a drive
# first create a mouning point folder, then mount
$ mkdir /media/folder_name
$ sudo mount -t auto /dev/sda6 /media/folder_name # or other name


# unmount a drive
$ sudo umount -t  auto /dev/sda6

# display currently active processes.
$ ps


# dispaly all running processes.
$ top

# get pid of a process
$ pidof process_name

# kill process
$ pkill mysqld
$ kill -SIGTERM pid

Friday, July 18, 2014

Some Important MySQL Commands

DB Backup Related

Database Backup

C:\Program Files\MySQL\MySQL Server 5.0\bin>mysqldump -u root -p123 DatabaseName > C:\FileName

Database Restore

C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -u root -p123 DatabaseName < C:\FileName

Export

 select * from TableName into outfile 'C:\\filename'  

Import

 load data local infile 'C:\\filename.txt' into table TableName;  

Delete duplicates for making unique column value

  1. Approach 1
  2.  ALTER IGNORE TABLE table_name ADD UNIQUE (col_name1, col_name2, ...);  
    
  3. Approach 2
  4.  CREATE TABLE new_table as select col1, ..., colN from old_table group by col1, ..., colN having count(*) &gt; 1;  
     DROP TABLE old_table;  
     RENAME TABLE new_table to old_table;   

Change column property

 ALTER TABLE table_name   
 ADD|DROP|CHANGE|MODIFY old_name new_name data_type;  

Max nth value

 SELECT * FROM employee ORDER BY salary DESC LIMIT (n - 1), 1  
Note: limit x,y
x: the record that you want to display(n-1) because it starts from 0.
y: the how many records you want to display.

Join

Self Join / Inner Join

 SELECT t1.name as Employee, t2.name as Manager   
 FROM table t1 , table t2   
 WHERE t1.id = t2.id;  

Outer Join

 SELECT table_1.name as Employee, COALESCE(table_2.name, 'No manager') as Manager  
 FROM table_1 LEFT OUTER JOIN table_2   
 ON table_1.id = table_2.id;  

Inner Join (bad way)

 SELECT column_name(s)  
 FROM table_1, table_2  
 WHERE table_1.column_name = table2.column_name  

Inner, Left, Right Join

 SELECT column_name(s)  
 FROM table_1  
 INNER | LEFT | RIGHT JOIN table_2  
 ON table_1.column_name = table_2.column_name  
Note: MySQL does not support FULL JOIN

Order by use in multiple column

 SELECT * FROM table_name   
 ORDER BY col1 DESC, col2 ASC, ... , col N ASC|DESC;  

Set Operation

Union

 SELECT column_name(s) FROM table_name1  
 UNION  
 SELECT column_name(s) FROM table_name2  

 SELECT column_name(s) FROM table_name1  
 UNION ALL  
 SELECT column_name(s) FROM table_name2  

Intersection

 SELECT column_name(s) FROM table_name1  
 WHERE column_name IN  
 (SELECT column_name FROM table_name2)  

Subtraction

 SELECT column_name(s) FROM table_name1  
 WHERE column_name NOT IN  
 (SELECT column_name FROM table_name2)  

Thursday, July 17, 2014

Basic Git Command

Install

# Installing git
$ apt-get install git

# Installing ui version of git
$ sudo apt-get install gitk

Configure

# Set your user name and e-mail address
--global option, because then Git will always use that information for anything you do on that system.
$ git config --global user.name "Ratul"
$ git config --global user.email 13ratul@gmail.com

# Configuring default editor
$ git config --global core.editor emacs

# Color console
$ git config --global color.diff auto
$ git config --global color.status auto
$ git config --global color.branch auto

# List all the settings Git
$ git config --list

# Check what Git thinks a specific key’s value
$ git config user.name

# Three ways to get the manual page (manpage) help for any of the Git commands
$ git help <verb>
$ git <verb> --help
$ man git-<verb>

Uses (Local)

# If you’re starting to track an existing project in Git, you need to go to the project’s directory and type
$ git init

# Few git add commands that specify the files you want to track
# Also used for Staging Modified Files
$ git add *.c
$ git add README

# For ignoring folder or files -

  1. create a file named '.gitignore'
  2. write the name of those file, folder or git regular expression

$ cat .gitignore

# Determine which files are in which state
$ git status

# To see what you’ve changed but not yet staged, type git diff with no other arguments
$ git diff

# Compares your staged changes to your last commit:
$ git diff --cached

# Committing Your Changes
$ git commit

# You can type your commit message inline with the commit command
$ git commit -m "my commit messages"

# Don’t have to run 'git add' command
$ git commit -a -m ’added & committed new files’

# Forget to add some files, or you mess up your commit message. If you want to try that commit again
$ git commit --amend

#Remove file from your tracked files (more accurately, remove it from your staging area) and then commit.
$ git rm fileName

# Rename or move a file in Git
# Equivalent to: $mv README.txt README | $git rm README.txt | $git add README
$ git mv fileNameOld fileNameNew

# Viewing the Commit History
$ git log

# Unstaging a Staged File
$ git reset HEAD fileName

# Unmodifying a Modified File
$ git checkout -- fileName

Uses (Remote)

Adding remote repository 

  1. first create a repository in github or others
  2. then, Adding Remote Repositories
  3. git remote add [shortname] [url]:
  4. use the string of [shortname] on the command line to get the whole URL

$ git remote add tst https://github.com/Asraf-Uddin-Ahmed/vbb.git

# To see which remote servers you have configured
$ git remote
$ git remote -v

Cloning or make copy of remote project
git clone URL
$ git clone git://github.com/schacon/ticgit.git

Pushing to Remotes
# Using -f not a good parctice
$ git push vbb master
$ git push -f vbb master

Fetch
# Get data from remote projects
# The command goes out to that remote project and pulls down all the data from that remote project that you don’t have yet but NOT MERGE THEM
git fetch [remote_name]
$ git fetch tst

Pull
# Get data from remote prjects & merge with desired branch
git pull [remote_name] [branch_name]
$ git pull test master

Removing Remotes
$ git remote rm vbb

Renaming Remotes
$ git remote rename tst test

# See more information about a particular remote
$ git remote show vbb

Advanced Linux Command

File

# Make change to file system (gui)
press -> alt + F2
type -> gksudo nautilus

Copy a file or folder with progress report.
# P => progress, h => huaman readable, r => recursive for folder.
# if folder name does not exist, 'rsync' auto create those folder.
$ rsync -Phr /path/of/source/file /path/of/destination/file

Detail info about a file or folder
$ stat file_or_folder_name

System

# Install *.deb files
sudo dpkg -i *.deb

# Start mysql
$  mysql --user=root --password=123

# Run a program or application without blocking terminal
$ program_name &
# Another approach
$ program_name
^Z # (ctrl + z) for stopping program
$ bg # run this program in background
$ fg # to run this program in foreground

# Format pendrive

  1. first unmount it
  2. then format

$ sudo mkfs.vfat /dev/sdb1 # vfat for fat32

# Shortcut creation
$ ln -s /path/of/main/folder/or/file /path/of/shortcut

# Check internet usage bandiwdth
$ nload -i 1024 -o 128