Tuesday, October 17, 2017

Script to set motd in linux machine

Just Copy and paste below mentioned commands in one file and assign executable permission to the file. it will set the motd in your machine

#!/bin/bash
#define the filename to use as output
motd="/etc/motd"
HOSTNAME=`uname -n`
KERNEL=`uname -r`
CPU=`nproc`
ARCH=`cat /etc/lsb-release | grep DISTRIB_DESCRIPTION`
# The different colours as variables
W="\033[01;37m" # WHITE
B="\033[01;34m" # BLUE
G="\033[01;32m" # GREEN 
R="\033[01;31m" # RED
X="\033[00;37m" # Light Gray
Y="\033[00;93m" # Yellow
C="\033[00;36m" # Cyan
M="\033[00;35m" # Magenta
RESET="\033[0m"
clear > $motd # to clear the screen when showing up

echo -e "                                                                      " >> $motd
echo -e "  $R _______   $M  _____    $X ______    $G _     _   $C ______ " >> $motd
echo -e "  $R      (_______) $M  / ___ \ $X  (_____ \ $G  | |   | |$C  |  ___ \ " >> $motd
echo -e "  $R       _____    $M | |   | |$X   _____) )$G  | |   | |$C  | | _ | | " >> $motd
echo -e "  $R      |  ___)   $M | |   | |$X  (_____ ( $G  | |   | |$C  | || || | " >> $motd
echo -e "  $R      | |       $M | |___| |$X        | | $G | |___| |$C  | || || | " >> $motd
echo -e "  $R      |_|       $M  \_____/  $X       |_| $G  \______|$C  |_||_||_| " >> $motd
echo -e " " >> $motd
echo -e " #=============================================================================# " >> $motd
echo -e "       $R Welcome $R to $R Motadata Forum                " >> $motd
echo -e "       $C Forum URL$C= http://forum.motadata.com                " >> $motd
echo -e "       $B KERNEL   $B= $KERNEL                                 " >> $motd
echo -e "       $M CPU Core $M= $CPU                              $RESET " >> $motd
echo -e "       $G ARCH     $G= $ARCH                              $RESET " >> $motd
echo -e "$C #=============================================================================#$RESET " >> $motd

Install / Uninstall JAVA In Linux/Unix

JAVA installation

# mkdir -p /usr/local/java

# tar xvzf /opt/jdk-8u131-linux-x64.tar.gz -C /usr/local/java

# echo "JAVA_HOME=/usr/local/java/jdk1.8.0_131" >> /etc/profile

# echo "PATH=$PATH:$HOME/bin:$JAVA_HOME/bin" >> /etc/profile

# echo "export JAVA_HOME" >> /etc/profile

# echo "export PATH" >> /etc/profile

# update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_131/bin/java" 1

# update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_131/bin/javac" 1

# update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_131/bin/javaws" 1

# update-alternatives --set java /usr/local/java/jdk1.8.0_131/bin/java

# update-alternatives --set javac /usr/local/java/jdk1.8.0_131/bin/javac

# update-alternatives --set javaws /usr/local/java/jdk1.8.0_131/bin/javaws

# source /etc/profile

--------------------

Delete/Remove Java

# sudo update-alternatives --remove "java" "/usr/lib/jvm/jdk<version>/bin/java"

# sudo update-alternatives --remove "javac" "/usr/lib/jvm/jdk<version>/bin/javac"

# sudo update-alternatives --remove "javaws" "/usr/lib/jvm/jdk<version>/bin/javaws"

verify that the symlinks were removed

# java -version

# javac -version

# which javaws

# cd /usr/lib/jvm

# sudo rm -rf jdk<version>

# sudo update-alternatives --config java

# sudo update-alternatives --config javac

# sudo update-alternatives --config javaws

# sudo vi  /etc/environment

Delete the line with JAVA_HOME 1

Java for MOtadata----------------------

# JAVA_HOME="/motadata/motadata/jdk/"

# source /etc/environment

# echo $JAVA_HOME
/motadata/motadata/jdk/

# echo "JAVA_HOME=/motadata/motadata/jdk">> /etc/profile

# echo "PATH=$PATH:$HOME/bin:$JAVA_HOME/bin" >> /etc/profile

# echo "export JAVA_HOME" >> /etc/profile

# echo "export PATH" >> /etc/profile

# update-alternatives --install "/usr/bin/java" "java" "/motadata/motadata/jdk/bin/java" 1

# update-alternatives: using /motadata/motadata/jdk/bin/java to provide /usr/bin/java (java) in auto mode

# update-alternatives --install "/usr/bin/javac" "javac" "/motadata/motadata/jdk/bin/javac" 1

# update-alternatives: using /motadata/motadata/jdk/bin/javac to provide /usr/bin/javac (javac) in auto mode

# update-alternatives --install "/usr/bin/javaws" "javaws" "/motadata/motadata/jdk/bin/javaws" 1      

update-alternatives: using /motadata/motadata/jdk/bin/javaws to provide /usr/bin/javaws (javaws) in auto mode

# update-alternatives --set java /motadata/motadata/jdk/bin/java

# update-alternatives --set javac /motadata/motadata/jdk/bin/javac

# update-alternatives --set javaws /motadata/motadata/jdk/bin/javaws

# source /etc/profile

# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Step by Step Installing Ubuntu Server 14.04 Trusty

Step 1. First, Download ubuntu server 14.04 lts from ubuntu official site

Step 2. After downloaded, burn ISO image of ubuntu server 14.04 into cd or usb flash disk. Set your computer booting from usb flash disk or cd/dvd. the system will boot (start) from the cd/dvd or USB flash drive and it appears.

Select what language you would like to install. I am going to use English language


Step 3. Select Install Ubuntu Server


Step 4. Select language that used for the installation process, default English


Step 5. Select location that will used for time zone and also for example to help select the system locale


Step 6. Configure keyboard layout


Step 8. Select country of origin for the keyboard. I am going to use English (US).


Step 9. Select the layout matching the keyboard for your machine. Default English


Step 10. Auto configure network


Step 11. Set Up users and password : Enter full name or real name for the new user, then select


Step 12. Set Up users and password : Enter name for your account, then select


Step 13. Set Up users and password : Enter password for the new user


Step 14. Set Up users and password : Re-enter password for the new user


Step 15. Set Up users and password : Answer Yes if you want to encrypt home directory. I recommend answer No because if your hard driver ever gets corrupted and you need to retrieve information it will be much easier to access it.


Step 16. Select your time zone


Step 17. Partitioning Disks: In this case i will used partitioning manual


Step 18. Add a Disk Partition Table


Step 19. Press return and the on the next menu select Yes and press return.


Step 20. We have a partition table on the first disk.


Step 21. Repeat those steps to create the partition table for the second disk drive.
Create the Partitions


Step 22. We need to start creating the partitions, Highlight the FREE SPACE on the first disk and press return.


Step 23. Create a new partition for /boot, I used the odd 0.8GB for this.


Step 24. I only use Primary partitions here but you can use primary or Logical/Extended, it makes little difference for this example.


Step 25. Put is at the beginning of the free disk space or not your choice.


Select the remaining free space on disk one.



For the swap partition use all the remaining disk space about 2GB.


Add LVM to the root Partition

Configure the Logical Volume Manager, again write the changes to the disk to continue. Create a volume group.



I called mine, vg0. But you can call it anything.


Select the the /dev/md1 this is our root partition which will use LVM so we can snap shot it for backups.


Create a Logical Volume, on the Volume group vg0.




We need to leave some space for the snapshot, so I choose to use 20978Mb. I changed the second digit from a 3 to a zero



Finish and go back to the main menu again.

Assign the Filesystems

Highlight the line under LVM VG vg0, LV lv_root to configure our root partition file system. Set it up as an EXT4 file system and a mount point of / (root). When it is all done it should look a bit like this


Highlight the line under RAID device #0. This is the unused space on the device. Set it up as an EXT4 file system and a mount point of /boot.


Now setup the swap partition on RAID device #2, it’s a similar process to the /boot partition.


Overall it should look like this


Sometimes when setting up the LVM you have to redo the /boot and swap partition if you configured those first, it’s rather annoying.

Finish with the partitioning and save the changes to disk.
Installing the System…


Configure HTTP Proxy: Select unless you are using a proxy, in this case we are not.


Configure Taskel: Select No automatic updates


Software Selection: Select [*] OpenSSH Server by pressing space key on keyboard, then select continue


Installing all Software.


Answer YES to Install the GRUB boot loader on a hardisk


Installation is Complete, Select Continue


Ubuntu Server 14.04 Trusty Tahr ready to use…

How to forward sflow and Netflow from Fortigate Firewall

Forward sflow from fortigate firewall


First Navigate to FortiGate CLI console.

Note: In FortiGate we can set one IP address at a time to forward flow, so if you want’s to forward flow on any IP you have to remove exiting and set the new one.
Execute the following command.

# config system sflow

Here you can see the list of ip address n which flow is forwarding.
If you want’s to set other IP need to remove the existing one by “unset” command.

# unset collector-ip

Now set the new IP address.

# set collector-ip 172.16.10.115

To verify configurations type “show”

# show


Type end to exit

#end

Forward Netflow from fortigate firewall

FG100E_MotaData # config system netflow
FG100E_MotaData (netflow) # unset collector-ip
FG100E_MotaData (netflow) # show
config system netflow
set collector-ip 163.172.175.100
end

FG100E_MotaData (netflow) # set collector-port 4738
FG100E_MotaData (netflow) # show full-configuration
config system netflow
set collector-ip 163.172.175.100
set collector-port 4738
set source-ip 0.0.0.0
set active-flow-timeout 30
set inactive-flow-timeout 15
set template-tx-timeout 30
set template-tx-counter 20
end

FG100E_MotaData (netflow) # end
FG100E_MotaData # config system sflow
FG100E_MotaData (sflow) # show
config system sflow
set collector-ip 192.168.2.172
set collector-port 4738
end

FG100E_MotaData (sflow) # unset collector-ip
FG100E_MotaData (sflow) # set collector-ip 163.172.175.100
FG100E_MotaData (sflow) # show
config system sflow
set collector-ip 163.172.175.100
set collector-port 4738
end

FG100E_MotaData (sflow) #

Send email using TELNET and Sendmail protocols

Send Email Using Telnet 

Note : We use the domain mailserver.co.in as an example. Be sure to replace with your own domain.
  • Open your command prompt.
  • Now, connect with telnet using the following command:
telnet mailserver.co.in 25

  • Type ehlo example.com. Some servers also accept helo in place of ehlo.

ehlo 
mailserver.co.in


  • Type mail from: sender@mailserver.co.in:


mail from: sender@mailserver.co.in


  • Type rcpt to: receiver@anydomain.com (replace with your actual recipient name):


rcpt to: 
receiver@anydomain.com


  • To write the message - type data, followed by your subject and message. To end the message, put a period on a line by itself and press enter:


data
Subject: My Telnet Test Email
Hello,
This is an email sent by Minder server using the telnet command.
Your friend,
Me
.


Type quit to 
exit telnet.


Now you should receive Test email sender@mailserver.co.in to receiver@anydomain.com