November 18

Linux: Check CPU statistics

dmidecode | less

Check for Hyper Threading state:
lscpu | grep -i -E “^CPU(s):|core|socket”

grep -E “cpu cores|siblings|physical id” /proc/cpuinfo | xargs -n 11 echo |sort |uniq

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

mpstat

sar

turbostat

nmon – not on Red Hat

iostat

Category: Linux | Comments Off on Linux: Check CPU statistics
November 18

Linux: List only directories

  1. Using echo
    Example: echo */, echo */*/

cs/ draft/ files/ hacks/ masters/ static/
cs/code/ files/images/ static/images/ static/stylesheets/

  1. Using ls only
    Example: ls -d */
    Here is exactly what I got:

cs/ files/ masters/
draft/ hacks/ static/
Or as list (with detail info): ls -dl */

  1. Using ls and grep
    Example: ls -l | grep “^d” Here is what I got:

drwxr-xr-x 24 h staff 816 Jun 8 10:55 cs
drwxr-xr-x 6 h staff 204 Jun 8 10:55 draft
drwxr-xr-x 9 h staff 306 Jun 8 10:55 files
drwxr-xr-x 2 h staff 68 Jun 9 13:19 hacks
drwxr-xr-x 6 h staff 204 Jun 8 10:55 masters
drwxr-xr-x 4 h staff 136 Jun 8 10:55 static

  1. Bash Script (Not recommended for filename containing spaces)
    Example: for i in $(ls -d */); do echo ${i%%/}; done
    Here is what I got:

cs
draft
files
hacks
masters
static
If you like to have ‘/’ as ending character, the command will be: for i in $(ls -d */); do echo ${i}; done

cs/
draft/
files/
hacks/
masters/
static/

Category: Linux | Comments Off on Linux: List only directories
November 18

Linux: Bash Script to ssh to multiple servers run a command and the seprately print the output for each server

Prerequisite: must have ssh key authentication configured

  1. Create a serverlist.txt file with a line by line list of servers.
  2. Create a shell file with the following code(eg. servicechecker.sh:

!/bin/bash

for host in $(cat serverlist.txt); do ssh “$host” “systemctl status isecespd” >”output.$host”; done

  1. chmod 755 script-filename
  2. ./script-filename
Category: Linux | Comments Off on Linux: Bash Script to ssh to multiple servers run a command and the seprately print the output for each server