Useful Linux Commands For NOC Work: Abstract
Useful Linux Commands For NOC Work: Abstract
Useful Linux Commands For NOC Work: Abstract
Abstract:
This page is intended to be a somewhat-loose flow of instructions which will serve as both a lesson when taken in order and as a
searchable reference.
NOC's Linux sandbox (aus-noc-dev.trionworld.priv) can be reached with PuTTY (http://www.putty.org/).
Objective/Goal:
Provide a fully funtional introduction to performing Tier 1 NOC procedures in a Linux environment.
Keywords:
This document is a:
Reference
Learning and applying these instructions will require the use of:
Your standard AD credentials should provide access; otherwise, Linux Engineering can set you up.
Caution:
In DOS, the Find command works like the Grep command in Linux. However, Find in Linux serves a different purpose and it is a
far-reaching and dangerous command. It should not be used without a specific purpose in mind and only with intentions and results
tested on a safe server.
Instruction Body:
The basics:
Copy from your Linux session: Use the mouse to highlight the text you want to copy. Text will automatically go to the clipboard.
Paste to your Linux session: Right-click in the Linux window. Items on the clipboard will insert at the cursor position.
Ctrl+c // Cancel current action. Some actions require a few repeated cancels to generate an interrupt.
Tab-complete // You can partially type something and press tab to resolve the remaining text.
cd /etc/httpd/conf // Move several levels ('/' aka "slash" or "root" through 'etc/' through 'httpd/' to 'conf') in one
command.
uptime // See how long it has been since the last bootup.
type file // Show a quick blurb about a 'file'. Note that in Unix-based systems everything is a file.
EX: type php
EX: type vi
EX: type ls
EX: type alias
host ipNumber // Find the hostname based on the IPv4 number given.
nslookup ipNumber // Find the arpa name (FQDN) based on the IP address given.
nslookup ipAddress // Find the IPv4 address based on the host name given.
File commands:
sudo chmod // '###' is where the numeric arguments are inserted. Change the permissions of a file so that certain
### groups,
users or everyone else may read, write and/or execute the file. Some numeric argument examples are:
764 = User can read, write and execute (7); user group can read and write (6); everyone else can read (4).
500 = User can read and execute only (5); everyone else is denied read, write and execution (00).
710 = User can read, write and execute (7); user group can execute only (1); everyone else is denied (0).
less fileName // Search through a file. Move down the lines with the spacebar and up the lines with the b key.
mv fileName // Rename the file. This does not preserve a duplicate file.
fileRenamed
rm fileName // Deletes a file. In Linux, there is no recycle bin – deleted files are immediately wiped away.
vi fileName // Create or edit a file using the vi editor. This is a huge subject and so only an introduction is mentioned
here. Most of what follows is done in Command Mode.
(in vi) i // Enter Insert Mode in vi to begin typing. This allows plain text style writing, copying and pasting.
(in vi) u // Undo the last command(s) or edit(s). Similar to Ctrl+Z in Windows.
(in vi) w // Save the file. You must have write permissions.
(in vi) w newFile // Save the file as a copy with a new name.
(in vi) q // Quit out of the vi editor. wq will save and quit.
facter
facter | grep up // This returns the various uptime info.
facter | egrep -i 'mem|har' // This returns memory and hardware info.
dmidecode // returns a very long list of hardware information.
dmidecode | less
dmidecode | grep -ih -8 processor | less // returns eight lines following every successful location of the word 'processor'.
dmidecode | egrep -ih -4 'vendor|product'
*There are many options that can be used with Top. You can either enter the option on the same command as calling top ("top -c")
or toggle the options on and off while Top is running by typing the letter, as shown below. The later has many more options, which
are called 'hotkeys'.
top
c // Option 'c' will show the command used to call the processes.
A // Splits the display into consumption groups.
f // Shows a menu of hotkey options.
ps aux
EX: ps aux | grep -i pierce // Return all processes being run by 'pierce' or by 'Pierce'.
EX: ps aux | grep -i pierce | grep -v grep // Same command but exclude the grep command
itself from the return.
EX: ps auxf | sort -nr -k 3 | head -20 // Return the top 20 CPU consumers.
For much more on processes, see Processes Supplement - Stopping, Starting, Restarting, Tracing
In the case of an unusually large event (like the domain's DNS system crashes) a Linux server's file system can become
vulnerable to corruption. As a means of avoiding corruption, every file on the server becomes 'read only', meaning not even the
operating system will be able to write to it or save things. NOC can quickly detect this problem and return the server from its 'safe
mode' status using the following sequence of commands.
1. ssh root@serverName // SSH into the server as root. If you suspect that the server is in a read-only state and the SSH
command freezes with no errors or successful connections, then the server is in worse shape than this instruction can
help with --probably its in a 'kernel panic' state that requires Linux Engineering to resolve.
2. cat /var/log/messages | tail -n 15 // 1st check. Read the last several log entries of 'messages' to see if a phrase
including "..aborted.." is present. Note this in the ticket.
3. touch /tmp/deleteMe // 2nd check. Since you are logged in as root, there should be nothing stopping you from creating
a simple file with Touch. If you receive an error stating "Read-only file system" then you will have to restart the server. If
the system lets you create the file then the server is not in a read-only state and troubleshooting for that state is complete
--don't do a restart.
4. shutdown -r now and wait several seconds // This restarts the server in a clean, safe way and should return it to
normal running condition rather than the read-only state. After 10 seconds or so, if the server is still active and NOT
FROZEN, then the restart is wonky and you will have to use the more aggressive restart command. EX: reboot