Tuesday, October 9, 2012

Httpd Status Code

Informational   1xx
Successful      2xx
Redirection     3xx
Client Error    4xx
Server Error    5xx

100 Continue
101 Switching Protocols
102 Processing (WebDAV) (RFC 2518)
103 Checkpoint
122 Request-URI too long (Microsoft/IE7)
--------------------------------------------
200 OK
201 Created (+ etag)
202 Accepted
203 Non-Authoritative Information
204 No Content (no body)
205 Reset Content (reset view)
206 Partial Content (+ range header)
207 Multi-Status (WebDAV) (RFC 4918)
226 IM Used (RFC 3229)
--------------------------------------------
300 Multiple Choices
301 Moved Permanently
302 Found
303 See Other (since HTTP/1.1)
304 Not Modified
305 Use Proxy (since HTTP/1.1)
306 Switch Proxy (no longer used)
307 Temporary Redirect (since HTTP/1.1)
308 Resume Incomplete
--------------------------------------------
400 Bad Request
401 Unauthorized
402 Payment Required (future)
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict (with the resource)
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Long
415 Unsupported Media Type
416 Requested Range Not Satisfiable
417 Expectation Failed
418 I'm a teapot (RFC 2324)
420 Enhance Your Calm (Twitter API)
422 Unprocessable Entity (WebDAV) (RFC 4918)
423 Locked (WebDAV) (RFC 4918)
424 Failed Dependency (WebDAV) (RFC 4918)
425 Unordered Collection (RFC 3648)
426 Upgrade Required (RFC 2817)
428 Precondition Required (RFC 2616 pending)
429 Too Many Requests (RFC 2616 pending)
431 Request Header Fields Too Large
444 No Response (Nginx)
449 Retry With (Microsoft)
450 Blocked by Windows Parental Controls (Microsoft)
499 Client Closed Request (Nginx)
--------------------------------------------
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported
506 Variant Also Negotiates (RFC 2295)
507 Insufficient Storage (WebDAV)(RFC 4918)
509 Bandwidth Limit Exceeded (Apache)
510 Not Extended (RFC 2774)
511 Network Authentication Required  (RFC 2616 pending)
598 Network read timeout error (Informal convention) 
599 Network connect timeout error (Informal convention)


Monday, October 8, 2012

TimeZone in Linux

Unix time, or POSIX time, is a system for describing points in time: it is the number of seconds elapsed since midnight UTC on the morning of January 1, 1970, not counting leap seconds.

Generic procedure to change timezone

Change directory to /etc

# cd /etc

Create a symlink to file localtime e.g. 
if you want to set up it to IST (Asia/Calcutta):

# ln -sf /usr/share/zoneinfo/Asia/Calcutta localtime

Please mote that in above example you need to use directory structure i.e. if you want to set the timezone to Calcutta (India) which is located in the Asia directory you will then have to setup using as above
Please do check with date command:

$ date

Output:
Mon Oct  8 16:39:56 IST 2012

Use of environment variable

You can use TZ environment variable to display date and time according to your or other timezones:

$ export TZ=Asia/Calcutta
$ date

Output:
Mon Oct  8 16:39:56 IST 2012

Here is the small script to check TIME from US-Chicago,Shanghai and India.

#!/bin/bash
echo -ne "India\t\t\c \t"
export TZ=Asia/Calcutta
date
echo -ne "Shanghai\t\c \t"
export TZ=Asia/Shanghai
date
echo -ne "US-Chicago\t\c \t"
export TZ=America/Chicago
date

.bashrc VS .bash_profile

Both the .bashrc and .bash_profile are scripts that might be executed when bash is invoked. The .bashrc file gets executed when you run bash using an interactive shell that is not a login shell. The .bash_profile only gets executed during a login shell. What does all this crap mean?

Login Shells (.bash_profile)

A login shell is a bash shell that is started with - or --login. The following are examples that will invoke a login shell.

# sudo su -
# bash --login
# ssh user@host

When BASH is invoked as a login shell, the following files are executed in the displayed order.

/etc/profile
~/.bash_profile
~/.bash_login
~/.profile

Although ~/.bashrc is not listed here, most default ~/.bash_profile scripts run ~/.bashrc.

Interactive Shells (.bashrc)

Interactive shells are those not invoked with -c and whose standard input and output are connected to a terminal. Interactive shells do not need to be login shells. Here are some examples that will evoke an interactive shell that is not a login shell.

# sudo su
# bash
# ssh user@host /path/to/command

In this case of an interactive but non-login shell, only ~/.bashrc is executed. In most cases, the default ~/.bashrc script executes the system's /etc/bashrc.
Be warned that you should never echo output to the screen in a ~/.bashrc file. Otherwise, commands like 'ssh user@host /path/to/command' will echo output unrelated to the command called.

Non-interactive shells

Non-interactive shells do not automatically execute any scripts like ~/.bashrc or ~/.bash_profile. Here are some examples of non-interactive shells.

# su user -c /path/to/command
# bash -c /path/to/command

For more information, see the bash man page.