Thursday, September 19, 2013

Ubuntu Recovery Mode documentation

https://wiki.ubuntu.com/RecoveryMode

Wednesday, July 3, 2013

Linux command line too to find public IP

Simply run : wget -qO - icanhazip.com

Friday, March 8, 2013

Delete files older than ‘N’ no of days.

Here I try to delete “.gz” files that are older than ‘n’ days.
However I make sure at least one file retain in the system after delete else no delete .


#!/bin/sh
# Author : SanjeewaF(21-02-2013)
#This file is to delete gzip files afterX no of days.
#Please only run them needed .


export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
CFG_FILE_PATH=/share/backups/reports/
FILE_TYPE=*.gz

NOW=$(date +"%Y-%m-%dT%H%M")
CFG_CUTTOFF_NO_DATES=45

if [ -w "$CFG_FILE_PATH" ]
then
noDeL=`find $CFG_FILE_PATH$FILE_TYPE -maxdepth 1 -nowarn -mtime +$CFG_CUTTOFF_NO_DATES 2>/dev/null | wc -l`
noExt=`find $CFG_FILE_PATH$FILE_TYPE -maxdepth 1 -nowarn 2>/dev/null | wc -l`

#echo "find $CFG_FILE_PATH$FILE_TYPE -maxdepth 1 -nowarn -mtime +$CFG_CUTTOFF_NO_DATES 2>/dev/null | wc -l"
#echo "find $CFG_FILE_PATH$FILE_TYPE -maxdepth 1 -nowarn 2>/dev/null | wc -l"

if [ $noDeL -ne 0 ] && [ $noExt -gt $noDeL ]
then

  echo "Deleting files older than $CFG_CUTTOFF_NO_DATES"
  find $CFG_FILE_PATH$FILE_TYPE -maxdepth 1 -nowarn -mtime +$CFG_CUTTOFF_NO_DATES -print


find $CFG_FILE_PATH$FILE_TYPE -maxdepth 1 -nowarn -mtime +$CFG_CUTTOFF_NO_DATES -print | xargs rm


else
  echo "unable delete all or no files del=$noDeL all=$noExt"
exit 1
fi
else
  echo "unable to find the writable directory $CFG_FILE_PATH"
fi

Tuesday, February 26, 2013

Check who's pinging my server and accessing other ports

sudo tcpdump -nnvXSs 0 -c2 icmp -- ping check
sudo tcpdump port 8080

Friday, February 8, 2013

Redirect ports in Ubuntu using iptables command



 Following code redirect all incoming traffic to port 7001 to 80


 sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 7001 -j REDIRECT --to-port 80

Following code redirect all incoming traffic to port 7001 to 8080

 sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 7002 -j REDIRECT --to-port 8080

Thursday, October 18, 2012

Change default Java version in Linux (Ubuntu)


I have decide to install jdk1.6.0_24 to my Ubuntu server 10.04 LTS and I want to make this as default java in my servere.

Note: if you laready have version you want to make default simple run the step 4 .

  1. Installed above jdk using jdk-6u24-linux-x64.bin in preferred directory
    in my case  : ‘/usr/lib/jvm’
  2. Once you installed I got following directory installed  ‘/usr/lib/jvm/jdk1.6.0_24’
  3. Now run following command :
    sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_24/jre/bin/java" 1
  4. Now time to select which java version you prefer , simple run and select the version
    sudo update-alternatives --config java
      eg :
       Selection    Path                                      Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/jdk1.6.0_24/jre/bin/java      1         manual mode

Press enter to keep the current choice[*], or type selection number: 2
That’s it your default java now set to target version.

  5. Same time you can change $JAVA_HOME and path variable to reflect changes . I prefer global change  
       so I edit /etc/profile and append
       export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_24
       export PATH=$PATH:$JAVA_HOME/bin


That’s it your server now refer to preferred java version .

Wednesday, October 17, 2012

Open Port scaning for linux(Ubuntu)



If you want ever want to find the ports that are open in a target server or network you may use
utility call `nmap` .
eg :
 in Ubuntu       1. Install the nmpa using -- > sudo apt-get install nmap
                       2.port scan for target ip  -- >  nmap -v -sT 192.168.01.98

you may get an output like below . Please use `nmap `Manual page to find more options

Starting Nmap 5.21 ( http://nmap.org ) at 2012-10-17 18:45 PGT
Initiating Ping Scan at 18:45
Scanning 192.168.01.98 [2 ports]
Completed Ping Scan at 18:45, 0.01s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 18:45
Completed Parallel DNS resolution of 1 host. at 18:45, 0.06s elapsed
Initiating Connect Scan at 18:45
Scanning 192.168.01.98 [1000 ports]
Discovered open port 80/tcp on 192.168.01.98
Discovered open port 8080/tcp on 192.168.01.98
Discovered open port 3306/tcp on 192.168.01.98
Discovered open port 445/tcp on 192.168.01.98
Discovered open port 22/tcp on 192.168.01.98
Discovered open port 21/tcp on 192.168.01.98
Discovered open port 139/tcp on 192.168.01.98
Discovered open port 8081/tcp on 192.168.01.98
Discovered open port 8090/tcp on 192.168.01.98
Completed Connect Scan at 18:45, 0.02s elapsed (1000 total ports)
Nmap scan report for 192.168.01.98
Host is up (0.00094s latency).
Not shown: 991 closed ports
PORT     STATE SERVICE
21/tcp   open  ftp
22/tcp   open  ssh
80/tcp   open  http
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
3306/tcp open  mysql
8080/tcp open  http-proxy
8081/tcp open  blackice-icecap
8090/tcp open  unknown

Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 0.13 seconds