27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

netstat −r is equivalent to route.<br />

uptime<br />

Shows how long the system has been running, along with associated statistics.<br />

bash$ uptime<br />

10:28pm up 1:57, 3 users, load average: 0.17, 0.34, 0.27<br />

hostname<br />

Lists the system's host name. This command sets the host name in an /etc/rc.d setup script<br />

(/etc/rc.d/rc.sysinit or similar). It is equivalent to uname −n, and a counterpart to the<br />

$HOSTNAME internal variable.<br />

bash$ hostname<br />

localhost.localdomain<br />

hostid<br />

bash$ echo $HOSTNAME<br />

localhost.localdomain<br />

Echo a 32−bit hexadecimal numerical identifier for the host machine.<br />

bash$ hostid<br />

7f0100<br />

This command allegedly fetches a "unique" serial number for a particular system.<br />

Certain product registration procedures use this number to brand a particular user<br />

license. Unfortunately, hostid only returns the machine network address in<br />

hexadecimal, with pairs of bytes transposed.<br />

The network address of a typical non−networked Linux machine, is found in<br />

/etc/hosts.<br />

bash$ cat /etc/hosts<br />

127.0.0.1 localhost.localdomain localhost<br />

sar<br />

As it happens, transposing the bytes of 127.0.0.1, we get 0.127.1.0, which<br />

translates in hex to 007f0100, the exact equivalent of what hostid returns, above.<br />

There exist only a few million other Linux machines with this identical hostid.<br />

Invoking sar (system activity report) gives a very detailed rundown on system statistics. This<br />

command is found on some commercial UNIX systems, but is not part of the base Linux distribution.<br />

It is contained in the sysstat utilities package, written by Sebastien Godard.<br />

bash$ sar<br />

Linux 2.4.7−10 (localhost.localdomain) 12/31/2001<br />

10:30:01 AM CPU %user %nice %system %idle<br />

10:40:00 AM all 1.39 0.00 0.77 97.84<br />

10:50:00 AM all 76.83 0.00 1.45 21.72<br />

11:00:00 AM all 1.32 0.00 0.69 97.99<br />

11:10:00 AM all 1.17 0.00 0.30 98.53<br />

11:20:00 AM all 0.51 0.00 0.30 99.19<br />

06:30:00 PM all 100.00 0.00 100.01 0.00<br />

Average: all 1.39 0.00 0.66 97.95<br />

readelf<br />

Chapter 13. System and Administrative Commands 223

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!