Monthly Archives: March 2014

linux screen

-ctrl a c -> create new window
-ctrl a A -> set window name
-ctrl a w -> show all window
-ctrl a 1|2|3|… -> switch to window n
-ctrl a ” -> choose window
-ctrl a ctrl a -> switch between window
-ctrl a d -> detach window
-ctrl a ? -> help
-ctrl a [ -> start copy, move cursor to the copy location, press ENTER, select the chars, press ENTER to copy the selected characters to the buffer
-ctrl a ] -> paste from buffer
How to start screen:

-screen -DR -> list of detached screen
-screen -r PID -> attach detached screen session
-screen -dmS MySession -> start a detached screen session
-screen -r MySession -> attach screen session with name MySession
Advanced:

-ctrl a S -> create split screen
-ctrl a TAB -> switch between split screens
If you created a new split screen, the current window is empty. either select an existing window (ctrl a “) or create a new split screen (ctrl a n).

-ctrl a Q -> Kill all regions but the current one.
-ctrl a X -> remove active window from split screen
-ctrl a O -> logout active window (disable output)
-ctrl a I -> login active window (enable output)

ipmitool

ipmitool is linux app that speaks the ipmi protocol to local and remote servers. Here are some example commands to get you started (read the extensive man page for more info):

Get a serial-over-lan console on rcXX: ipmitool -I lanplus -H rcXXipmi -U ADMIN -a sol activate
Get the power status: ipmitool -I lanplus -H rcXXipmi -U ADMIN chassis status
Reboot a machine: ipmitool -I lanplus -H rcXXipmi -U ADMIN power reset
Force PXE boot on the next boot only: ipmitool -I lanplus -H rcXXipmi -U ADMIN chassis bootdev pxe
(This will cause the machine to reinstall all its software on the next boot)
Reboot the IPMI card: ipmitool -I lanplus -H rcXXipmi -U ADMIN mc reset cold
Get sensor output: ipmitool -I lanplus -H rcXXipmi -U ADMIN sdr list
Get the error log: ipmitool -I lanplus -H rcXXipmi -U ADMIN sel elist
NB: Our SuperMicro machines appear to log SMART failures as OEM #0xff, e.g. ipmi

lsof

lsof is one of the little known but very powerfull utility in Linux. Man pages basically says that lsof: list open files. But you can use it for managing and tracking network connections, you can list open ports, identify connections currently being made to your system, and determine what resources a process is using. Not only that, but you can also determine what processes a particular user has and find detailed information about file and directory usage. Here some example usages:

List all open files in system:
lsof

List all network connections:
lsof -i

List all UDP connections:
lsof -iUDP

List connections on specific port number:
lsof -i :80

List connections on specific host:
lsof [email protected]

List connection on specifics host and port:
lsof [email protected]:80

List all files opened by user fred:
lsof -u fred

List all files which opened by specific command:
lsof -c mysqld

List all process which using a specific file:
lsof /var/run/mysqld/mysqld.sock

List all processes which opens files under specific directory:
lsof +d /etc/passwd

List all the open files used by a specific process with process id:
lsof -p 8729

Linux Increase Local Port Range

If your Linux server is opening lots of outgoing network connection, you need to increase local port range. By default range is small. For example squid proxy server can come under fire if it runs out of ports.

You can use sysctl command to to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/. Please note that this hack is only useful for high bandwidth, busy Linux servers or large scale grid servers.

To find current range type

$ sysctl net.ipv4.ip_local_port_range

Output:

net.ipv4.ip_local_port_range = 32768 61000
Set new local port range

You can set the range with the following command:
# echo 1024 65535 > /proc/sys/net/ipv4/ip_local_port_range

OR
$ sudo sysctl -w net.ipv4.ip_local_port_range=”1024 64000″

You may need to edit /etc/sysctl.conf file, to make changes to /proc filesystem permanently i.e. append the following to your /etc/sysctl.conf file:
# increase system IP port limits
net.ipv4.ip_local_port_range = 1024 65535