Ubuntu install gnome classic from command line

Recent versions of Ubuntu is coming with Unity desktop which are bit heavy.

We can also install gnome classic from command line.

To install gnome classic or gnome session fallback use following command:

$ sudo apt-get install  gnome-session-fallback

After installing just logout from this session and relogin.

Before logging in click the icon(Ubuntu Icon) in the top right of the Login box and select Gnome classic and login to you account.

This will take to gnome classic desktop.

Lighttpd – block user agent

 

In lighttpd we can block or deny access to a specific user agent.

Syntax to block user agent:

$HTTP["useragent"] =~ "User agent name" {url.access-deny = ( "" )}

where “User agent name” is any user agent.

Example:

$HTTP["useragent"] =~ "Xenu Link Sleuth" {url.access-deny = ( "" )}

Above example will block all requests with user agent name “Xenu Link Sleuth”.

Nmap – Scan for open ports

 

nmap is a network exploration tool and security/port scanner.

We can list all open ports using nmap for a given IP/Host.

Use following command to list all open ports:

$ sudo nmap -v -sS 192.168.1.1

Use following command to scan specific ports:

$ nmap -sS -O -p80,8080 192.168.1.1

To can specific range of ports(scan from port 80 to 100):

$ sudo nmap -sS -O -p80-100 192.168.1.1

Ping all IP’s in a subnet

 

We can use nmap command to ping all IP’s in subnet.

If you don’t have nmap installed in your machine install nmap with following command:

$ apt-get install nmap

Use following command to ping all IP’s in a subnet:

$ nmap -n -sP 192.168.2.0/26

Output:

Starting Nmap 5.21 ( http://nmap.org ) at 2014-06-30 17:04 PDT
Nmap scan report for 192.168.2.1
Host is up (0.00073s latency).
Nmap scan report for 192.168.2.2
Host is up (0.0011s latency).
Nmap scan report for 192.168.2.4
Host is up (0.0010s latency).
Nmap done: 64 IP addresses (3 hosts up) scanned in 0.62 seconds

In above output we can see all reachable IP’s.

 

mutt – send mails with attachments

 

By using mutt we can send mails with attachments from command line.

Install mutt:

$ apt-get install mutt

Send mail with attachment:

$ mutt -s "PFA" -a attachment.txt user@example.com < body.txt

or

$ echo "body text here" | mutt -s "PFA" -a t.txt user@example.com

Send mail without attachment:

$ mutt -s "PFA" user@example.com < body.txt

or

$ echo "body text here"  | mutt -s "PFA" user@example.com

Python convert list values to int values

 

I have a list with int values as strings as following:

>>> mylist = ['1', '2', '3', '4']

>> mylist

['1', '2', '3', '4']

I would like to convert all values in mylist to int’s.

I used following code to convert values of lists to int’s:

>>> output = map(int, mylist)

>>> output

[1, 2, 3, 4]

Now just observer both list output values, all values in mylist are strings and all values in output list are int’s.

CentOS – Hostname Change

 

To change host name in CentOS use following steps:

Open /etc/sysconfig/network file

$ vim /etc/sysconfig/network

Now modifiy HOSTNAME= value

HOSTNAME=my.domain.com

my.domain.com is desired host for my machine, similarly we can use other valid domain names.

Next edit /etc/hosts file, here we need to change the host that is associated to your main IPaddress for your server.

192.168.1.10   my.domain.com my

After completing above two changes restart network by using following command:

$ service network restart 

Now run hostname command:

$ hostname

Output:

my.domain.com

Above procedure will work both in CentOS 5 and 6 versions.

keepalived mail notification

 

To get mail alerts from keepalived(on every start change from MASTER to BACKUP or BACKUP to Master) we need to add following code in keepalived.conf file:

global_defs {
  notification_email {
    user@hostname.com
  }
  notification_email_from lb-alert@hostname.com
  smtp_server your.smtpserver..com
  smtp_connect_timeout 30
}

Next add following line in keepalived.conf’s vrrp_instance VI_1 block:

smtp_alert

After adding smtp_alert in vrrp_instance VI_1 block your code looks like below:

vrrp_instance VI_1 {
  ...Your Code...
  ...Your Code...
  ...Your Code...
  smtp_alert
  ...Your Code...
  ...Your Code...
  ...Your Code...
}

After making above two changes restart keepalived.

$ service keepalived restart