GIT –  System Admin Tool Linux : Set Date and Time Find Out the Server Model, Linux Find Out CPU Architecture Information, Find Information About The Process Including All Command Line Parameters, Linux Network Statistics Tools Commands.

1. HowTo: UNIX Set Date and Time Command

Irecently noticed that one of my UNIX servers was about 4 hours behind the correct time. I wanted to correct the date and time manually. How do I set date and/or time under UNIX operating systems using command line options?

The date command displays the current day, date, time, and year as well as it can set both the date and time for you. To see the current date and time, enter:

$ date

You must be login as to set / change date under UNIX. The syntax to set date and time under UNIX and UNIX like operating system is as follows:

date MMddhhmm[[cc]yy]

Where,

  • MM : Month (two-digit numeric month)
  • dd : Day (two-digit numeric day i.e. day of month)
  • hh : Hour
  • mm : Minutes (30)
  • cc : First two digits of the year (10)
  • yy : Last two digits of the year (2010).

To set date to April 27, 2010 8:00am under HP-UX, AIX, Sun Solaris or UNIX like operating system, enter:

date 042708002010

HP-UX UNIX Set Date Example Using Various Formats

Using the mmddHHMM[[cc]yy][.ss] format, set date:

date 010709342000
date 0107093400.00
date 010709342000.00

Using the [[cc]yy]mmddHHMM[.ss] format:

date 0001070934
date 200001070934
date 200001070934.00

Using the mmddHHMM[.ss[[cc]yy]] format:

date 01070934.0000
date 01070934.002000

IBM AIX UNIX Set Date

To set the date and time under AIX UNIX, enter:

date 0217185010

The above sets the date and time to Wed Feb 17 18:50:00 CST 2010.

Getting Help About date Command

You can also view the manual page on date using the following command:

$ man date

2. UNIX: Find Out the Server Model

How do I find out my UNIX server model? What is my UNIX server model?

To display hardware (server or workstation) model information under UNIX use the following command.

HP-UX UNIX Command

The model command displays the machine hardware model. It may also display the manufacturer, product names, or other information:

# model

Sample outputs:

ia64 hp server g4000

Please note that /usr/bin/arch -k provides the same information:

# /usr/bin/arch -k

machinfo Command: Print Machine Information

The machinfo command displays information about the machine such as system processors, firmware revisions, and amount of memory on the system. This output consists of the HP-UX operating system’s view of the system configuration, as opposed to the entire physical hardware platform. The information about processors and memory reflects the configuration of the physical or virtual partition:

# machinfo

Sun / Oracle Solaris UNIX Command

The prtconf command provides the same info as model command under Sun Solaris UNIX, enter:

# prtconf

If you are using an UltraSparc, try:

# /usr/platform/sun4u/sbin/prtdiag -v

Please note that the prtdiag command displays system configuration and diagnostic information on sun4u, sun4v, and x86 systems only. The psrinfo command displays information about processors, enter:

# psrinfo

AIX UNIX Command

You need to run the prtconf command as follows:

# prtconf

To find out if the hardware is 32-bit or 64-bit, enter:

# bootinfo -y

You can also use the lscfg command to displays configuration, diagnostic, and vital product data (VPD) information about the IBM AIX UNIX system, enter:

# lscfg

The uname -M command can displays the system model name:

# uname -M

3. Linux Find Out CPU Architecture Information

How do I find out my CPU architecture information under Linux operating systems?

You can use /proc/cpuinfo file or use the lscpu command to get info about CPU architecture. It will display information like:

  • Number of CPUs
  • Threads
  • Cores
  • Sockets
  • NUMA nodes
  • Information about CPU caches,
  • CPU family, model and stepping.
  • in human-readable format. Alternatively, it can print out in parsable
  • format including how different caches are shared by different CPUs,
  • which can also be fed to other programs.

Open a terminal and type the following command:

$ less /proc/cpuinfo

OR

$ lscpu

Sample outputs:

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
CPU(s):                8
Thread(s) per core:    2
Core(s) per socket:    4
CPU socket(s):         1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 30
Stepping:              5
CPU MHz:               1199.000
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              8192K

4. Unix / Linux: Find Information About The Process Including All Command Line Parameters

I’m using ps command to read a snapshot of the current processes under Unix / Linux operating systems. However, ps -e or ps aux only displays command / processes names. I need to see complete information about the process including all parameters passed to it. How do I see it under Unix / Linux using ps command?

To see every process on the Unix like system use the following standard syntax:

ps -e
ps -ef
ps -eF
ps -ely
ps axu

Sample outputs:

UID        PID  PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
root         1     0  0  2101   792   6 11:17 ?        00:00:02 init [2]
root         2     0  0     0     0   1 11:17 ?        00:00:00 [kthreadd]
root         3     2  0     0     0   0 11:17 ?        00:00:00 [ksoftirqd/0]
root         6     2  0     0     0   0 11:17 ?        00:00:00 [migration/0]
root         7     2  0     0     0   0 11:17 ?        00:00:00 [watchdog/0]
root         8     2  0     0     0   1 11:17 ?        00:00:00 [migration/1]
root        10     2  0     0     0   1 11:17 ?        00:00:00 [ksoftirqd/1]
root        12     2  0     0     0   1 11:17 ?        00:00:00 [watchdog/1]
root        13     2  0     0     0   2 11:17 ?        00:00:00 [migration/2]
root        15     2  0     0     0   2 11:17 ?        00:00:00 [ksoftirqd/2]
....
....
root      3756     2  0     0     0   4 11:44 ?        00:00:00 [kworker/4:2]
root      3757     2  0     0     0   6 11:44 ?        00:00:02 [kworker/6:0]
root      3781     2  0     0     0   0 11:46 ?        00:00:00 [kworker/0:0]
root      3789     2  0     0     0   3 11:46 ?        00:00:00 [kworker/3:0]
root      3994     2  0     0     0   2 11:48 ?        00:00:00 [kworker/2:0]

However, this will not display all command line args passed to the command due to screen size limitations. You need to add ‘ww’ after aux, as follows for complete information about the process including all command line parameters:

ps auxww

Sample outputs:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.1  0.0   8404   792 ?        Ss   11:17   0:02 init [2]
root         2  0.0  0.0      0     0 ?        S    11:17   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    11:17   0:00 [ksoftirqd/0]
root         6  0.0  0.0      0     0 ?        S    11:17   0:00 [migration/0]
root         7  0.0  0.0      0     0 ?        S    11:17   0:00 [watchdog/0]
root         8  0.0  0.0      0     0 ?        S    11:17   0:00 [migration/1]
root        10  0.0  0.0      0     0 ?        S    11:17   0:00 [ksoftirqd/1]
root        12  0.0  0.0      0     0 ?        S    11:17   0:00 [watchdog/1]
root        13  0.0  0.0      0     0 ?        S    11:17   0:00 [migration/2]
....

The -w option is for wide output. Use this option twice for unlimited width. You can use shell pipes to filter output as follows:

$ ps auxww | grep pid
$ ps auxww | grep mysqld
$ ps auxww | grep --color mysqld

Sample outputs:

Fig.01: ps auxww in Action ( click to enlarge )

Controlling ps Output

The -o option to ps command can be used to see ouput in user-defined format. In this example, see every process with a user-defined format:

ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
ps -eopid,tt,user,fname,tmout,f,wchan

You can only see PID, command and its args using the following format:

ps axo pid,command,args

Sample outputs:

Unix / Linux ps command output format control command

A Note About Default Output Format

Set PS_FORMAT shell variable to override default output format. You may set this to a format string of the type used for the -o option.

export PS_FORMAT=pid,command,args
ps auxww

5. Linux Network Statistics Tools / Commands

How do I find out the current network interface throughput statistics on Linux ( or Debian based distro)? How do I see current kernel snmp counters and network interface statistics on Linux operating systems?

You can use any one of the following commands:

nstat command : Network Statistics Tool

Type the following command:

# nstat

Sample outputs:

#kernel
IpInReceives                    133243             0.0
IpInDelivers                    133243             0.0
IpOutRequests                   92904              0.0
IcmpOutErrors                   97                 0.0
IcmpOutTimeExcds                97                 0.0
IcmpMsgOutType3                 97                 0.0
TcpActiveOpens                  538                0.0
TcpEstabResets                  56                 0.0
TcpInSegs                       129837             0.0
TcpOutSegs                      89720              0.0
TcpRetransSegs                  42                 0.0
TcpOutRsts                      704                0.0
UdpInDatagrams                  3255               0.0
UdpNoPorts                      97                 0.0
UdpOutDatagrams                 3270               0.0
Ip6OutNoRoutes                  206                0.0
TcpExtTW                        141                0.0
TcpExtDelayedACKs               508                0.0
TcpExtDelayedACKLocked          1                  0.0
TcpExtDelayedACKLost            42                 0.0
TcpExtTCPHPHits                 117659             0.0
TcpExtTCPPureAcks               2158               0.0
TcpExtTCPHPAcks                 605                0.0
TcpExtTCPSackRecovery           1                  0.0
TcpExtTCPLossUndo               16                 0.0
TcpExtTCPSackFailures           4                  0.0
TcpExtTCPFastRetrans            1                  0.0
TcpExtTCPSlowStartRetrans       3                  0.0
TcpExtTCPTimeouts               33                 0.0
TcpExtTCPDSACKOldSent           40                 0.0
TcpExtTCPDSACKRecv              5                  0.0
TcpExtTCPAbortOnData            120                0.0
TcpExtTCPAbortOnClose           55                 0.0
TcpExtTCPSackShiftFallback      9                  0.0
IpExtInOctets                   180131682          0.0
IpExtOutOctets                  7289106            0.0

ss command : Utility To Investigate Sockets

To see summary of stats, enter:

# ss -s

Sample outputs:

Total: 786 (kernel 804)
TCP:   65 (estab 40, closed 7, orphaned 0, synrecv 0, timewait 6/0), ports 56
Transport Total     IP        IPv6
*	  804       -         -
RAW	  1         1         0
UDP	  12        9         3
TCP	  58        52        6
INET	  71        62        9
FRAG	  0         0         0

netstat command : The Old Good Utility To Show Sockets

To see a table of all network interfaces and its summary, enter:

# netstat -i

Sample outputs:

Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500 0    941022      0      0 0        688165      0      0      0 BMRU
lo        16436 0      9304      0      0 0          9304      0      0      0 LRU
ppp0       1496 0      3784      0      0 0          4177      0      0      0 MOPRU

To see summary statistics for each protocol, enter:

# netstat -s

Sample outputs:

Ip:
    1092065 total packets received
    0 forwarded
    0 incoming packets discarded
    1091681 incoming packets delivered
    798913 requests sent out
    895 dropped because of missing route
    759 reassemblies required
    375 packets reassembled ok
Icmp:
    17 ICMP messages received
    0 input ICMP message failed.
    ICMP input histogram:
        timeout in transit: 8
        echo replies: 9
    1747 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 1730
        echo request: 17
IcmpMsg:
        InType0: 9
        InType11: 8
        OutType3: 1730
        OutType8: 17
Tcp:
    4822 active connections openings
    1129 passive connection openings
    457 failed connection attempts
    165 connection resets received
    7 connections established
    1062519 segments received
    771394 segments send out
    7158 segments retransmited
    6 bad segments received.
    2578 resets sent
Udp:
    20846 packets received
    1730 packets to unknown port received.
    0 packet receive errors
    19242 packets sent
UdpLite:
TcpExt:
    71 invalid SYN cookies received
    8 resets received for embryonic SYN_RECV sockets
    142 packets pruned from receive queue because of socket buffer overrun
    2109 TCP sockets finished time wait in fast timer
    84 packets rejects in established connections because of timestamp
    19454 delayed acks sent
    6 delayed acks further delayed because of locked socket
    Quick ack mode was activated 7306 times
    1 packets directly queued to recvmsg prequeue.
    1 bytes directly received in process context from prequeue
    823921 packet headers predicted
    24412 acknowledgments not containing data payload received
    10150 predicted acknowledgments
    242 times recovered from packet loss by selective acknowledgements
    33 congestion windows recovered without slow start by DSACK
    335 congestion windows recovered without slow start after partial ack
    336 TCP data loss events
    TCPLostRetransmit: 35
    1 timeouts after reno fast retransmit
    156 timeouts after SACK recovery
    116 timeouts in loss state
    461 fast retransmits
    5 forward retransmits
    608 retransmits in slow start
    2073 other TCP timeouts
    62 SACK retransmits failed
    43074 packets collapsed in receive queue due to low socket buffer
    8499 DSACKs sent for old packets
    101 DSACKs sent for out of order packets
    308 DSACKs received
    9 DSACKs for out of order packets received
    427 connections reset due to unexpected data
    122 connections reset due to early user close
    28 connections aborted due to timeout
    TCPDSACKIgnoredOld: 3
    TCPDSACKIgnoredNoUndo: 60
    TCPSpuriousRTOs: 4
    TCPSackShifted: 282
    TCPSackMerged: 740
    TCPSackShiftFallback: 1017
IpExt:
    InMcastPkts: 47
    OutMcastPkts: 51
    InBcastPkts: 1
    InOctets: 1341508973
    OutOctets: 72525352
    InMcastOctets: 8649
    OutMcastOctets: 7519
    InBcastOctets: 328

ip / ifconfig command : Configure or Show a Network Interface Info

Type the following command:

# ifconfig

OR

# /sbin/ifconfig

OR

# ifconfig eth0

eth0      Link encap:Ethernet  HWaddr b8:ac:6f:65:31:e5
          inet addr:192.168.1.5  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::baac:6fff:fe65:31e5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:966334 errors:0 dropped:0 overruns:0 frame:0
          TX packets:703297 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1186255648 (1.1 GiB)  TX bytes:73968238 (70.5 MiB)
          Interrupt:17
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:9666 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9666 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1399578 (1.3 MiB)  TX bytes:1399578 (1.3 MiB)
ppp0      Link encap:Point-to-Point Protocol
          inet addr:10.1.11.70  P-t-P:10.0.31.18  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1496  Metric:1
          RX packets:3784 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4177 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:2400265 (2.2 MiB)  TX bytes:275983 (269.5 KiB)

To display network interface statistics, enter:

# ip -s link

Sample outputs:

1: lo:  mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    RX: bytes  packets  errors  dropped overrun mcast
    1444187    9960     0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    1444187    9960     0       0       0       0
2: eth0:  mtu 1500 qdisc mq state UP qlen 1000
    link/ether b8:ac:6f:65:31:e5 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    1221956483 991501   0       0       0       24
    TX: bytes  packets  errors  dropped carrier collsns
    75623937   720272   0       0       0       0
3: wlan0:  mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 00:21:6a:ca:9b:10 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    0          0        0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    0          0        0       0       0       0
4: pan0:  mtu 1500 qdisc noop state DOWN
    link/ether 4a:c7:5f:0e:8e:d8 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    0          0        0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    0          0        0       0       0       0
8: ppp0:  mtu 1496 qdisc pfifo_fast state UNKNOWN qlen 3
    link/ppp
    RX: bytes  packets  errors  dropped overrun mcast
    2419881    3848     0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    284151     4287     0       0       0       0

sar command: Display Network Stats

Type the following command (you need to install and enable sar via sysstat package):

sar -n DEV

Linux 2.6.32-220.2.1.el6.x86_64 (www.gocit.vn)    Tuesday 13 March 2012   _x86_64_        (2 CPU)
12:00:01  CDT     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
12:10:01  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:10:01  CDT      eth0    127.13    121.32     95.45     18.34      0.00      0.00      0.00
12:10:01  CDT      eth1     98.48    110.62     16.72     96.33      0.00      0.00      0.00
12:20:01  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:20:01  CDT      eth0    139.95    133.41    106.30     19.95      0.00      0.00      0.00
12:20:01  CDT      eth1    110.65    121.85     18.14    107.13      0.00      0.00      0.00
12:30:01  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:30:01  CDT      eth0    147.85    132.49    115.78     20.45      0.00      0.00      0.00
12:30:01  CDT      eth1    111.88    127.39     18.61    117.65      0.00      0.00      0.00
12:40:01  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:40:01  CDT      eth0    136.75    124.64    105.24     19.48      0.00      0.00      0.00
12:40:01  CDT      eth1    101.65    115.32     17.58    104.50      0.00      0.00      0.00
12:50:01  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:50:01  CDT      eth0    131.45    125.69     96.49     19.58      0.00      0.00      0.00
12:50:01  CDT      eth1    101.41    111.31     17.54     96.78      0.00      0.00      0.00
01:00:01  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
01:00:01  CDT      eth0    140.30    133.27    102.17     20.75      0.00      0.00      0.00
01:00:01  CDT      eth1    106.90    119.51     18.53    103.09      0.00      0.00      0.00
01:10:01  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
01:10:01  CDT      eth0    152.03    127.74    125.56     19.85      0.00      0.00      0.00
01:10:01  CDT      eth1    115.60    134.57     18.73    126.96      0.00      0.00      0.00
01:20:01  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
01:20:01  CDT      eth0    138.55    130.55    103.03     20.20      0.00      0.00      0.00
....
..
....
..
.
01:00:01  CDT      eth1    156.82    169.48     28.83    138.49      0.00      0.00      0.00
01:10:01  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
01:10:01  CDT      eth0    215.19    194.82    163.11     30.99      0.00      0.00      0.00
01:10:01  CDT      eth1    162.49    183.79     28.36    163.70      0.00      0.00      0.00
01:20:01  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
01:20:01  CDT      eth0    200.20    192.23    140.64     30.93      0.00      0.00      0.00
01:20:01  CDT      eth1    153.60    166.96     27.32    140.26      0.00      0.00      0.00
01:30:01  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
01:30:01  CDT      eth0    111.98    103.58     79.12     16.52      0.00      0.00      0.48
01:30:01  CDT      eth1     87.50     95.58     14.74     79.35      0.00      0.00      0.00
Average:        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
Average:           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:         eth0    211.21    196.20    156.18     31.20      0.00      0.00      0.01
Average:         eth1    159.10    174.52     28.00    149.95      0.00      0.00      0.00

Or type the following command:

# sar -n DEV 1 3

Sample outputs:

Linux 2.6.32-220.2.1.el6.x86_64 (www.gocit.vn)    Tuesday 13 March 2012   _x86_64_        (2 CPU)
01:44:03  CDT     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
01:44:04  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
01:44:04  CDT      eth0    161.70    154.26    105.20     26.63      0.00      0.00      0.00
01:44:04  CDT      eth1    145.74    142.55     25.11    144.94      0.00      0.00      0.00
01:44:04  CDT     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
01:44:05  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
01:44:05  CDT      eth0    162.14    156.31    107.46     42.18      0.00      0.00      0.00
01:44:05  CDT      eth1    135.92    138.83     39.38    104.92      0.00      0.00      0.00
01:44:05  CDT     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
01:44:06  CDT        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
01:44:06  CDT      eth0    303.92    293.14    272.91     37.40      0.00      0.00      0.00
01:44:06  CDT      eth1    252.94    290.20     34.87    263.50      0.00      0.00      0.00
Average:        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
Average:           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:         eth0    210.37    202.34    163.19     35.66      0.00      0.00      0.00
Average:         eth1    178.93    191.64     33.36    171.60      0.00      0.00      0.00
Theo : cyberciti ( System Admin Tool Linux )
Bài viết này nằm trong dự án  website : www.gocit.vn, forum hổ trợ forum.gocit.vn , xem thêm tại link http://www.gocit.vn/du-an-linux-toan-tap/
Thảo luận bài viết tại forum : http://forum.gocit.vn/threads/system-admin-tool-linux.458/
Print Friendly

Comments

comments

Bài viết liên quan