Obtain and setting the BMC date and time using ipmitool

There are times when viewing the ipmi logs via the following command, the date and time is incorrect.

# ipmitool sel elist last 20
 2b7 | 07/26/2022 | 13:53:16 | Critical Interrupt | Bus Correctable error | Asserted
 2b8 | 07/26/2022 | 13:53:16 | Critical Interrupt | Bus Correctable error | Asserted
 2b9 | 07/26/2022 | 13:53:16 | Critical Interrupt | Bus Correctable error | Asserted
 2ba | 07/26/2022 | 13:53:16 | Critical Interrupt | Bus Correctable error | Asserted
 2bb | 07/26/2022 | 13:53:16 | Critical Interrupt | Bus Correctable error | Asserted
 2bc | 07/26/2022 | 13:53:16 | Critical Interrupt | Bus Correctable error | Asserted
 2bd | 07/26/2022 | 13:53:16 | Power Supply PSU1_STATUS | Power Supply AC lost | Asserted
 2be | 07/26/2022 | 13:53:16 | Power Supply PSU1_STATUS |  | Deasserted
 2bf | 07/26/2022 | 22:19:23 | System ACPI Power State ACPI_PWR_STATE | Legacy ON state | Asserted
 2c0 | 07/26/2022 | 22:19:23 | Processor CPU0_PRESENT | Presence detected | Asserted
 2c1 | 07/26/2022 | 22:19:23 | Processor CPU1_PRESENT | Presence detected | Asserted
 2c2 | 07/26/2022 | 22:19:58 | Power Supply PSU0_STATUS | Presence detected | Asserted
 2c3 | 07/26/2022 | 22:19:58 | Power Supply PSU0_STATUS |  | Asserted
 2c4 | 07/26/2022 | 22:19:58 | Power Supply PSU1_STATUS | Presence detected | Asserted
 2c5 | 07/26/2022 | 22:19:58 | Power Supply PSU1_STATUS |  | Asserted
 2c6 | 07/26/2022 | 22:19:59 | System ACPI Power State ACPI_PWR_STATE | Legacy ON state | Asserted
 2c7 | 07/26/2022 | 22:19:59 | Processor CPU0_PRESENT | Presence detected | Asserted
 2c8 | 07/26/2022 | 22:19:59 | Processor CPU1_PRESENT | Presence detected | Asserted

To obtain current BMC time according to the BMC

# ipmitool sel time get
08/16/2022 00:25:06

Dynamically change the BMC time

# ipmitool sel time set "$(date '+%m/%d/%Y %H:%M:%S')"
08/15/2022 18:27:41

Verify the new settings:

# ipmitool sel time get
08/15/2022 18:28:04
Posted in Data Storage, IPMI | Tagged , | Leave a comment

Mapping MAC Numeric Keyboard on VMware Console using Karabiner Elements

I regular problem of mine was launching the VMware remote console on my MAC, and being unable to use the Numeric Keypad.

I used Karabiner Elements to create my own custom rules that allow me to do this.

First step is to install Karabiner Elements

Next, I prefer to use terminal, and navigate to ~/.config/karabiner/assets/complex_modifications

Inside that folder I vi filename ben-vmware-keyboard-mapping

*note, I only prefix my name on the filename so that I know it is my custom rule in Karabiner. It is completely optional!

Next, I paste the following into the file.

{
  "title": "Map Keypad when using VMWare Console",
  "rules": [
      {
      "description": "BEN: VMware Console Use Keypad 0 key as 0",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_0"
           },
          "to": [
            {
            "key_code": "0"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad 1 key as 1",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_1"
           },
          "to": [
            {
            "key_code": "1"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad 2 key as 2",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_2"
           },
          "to": [
            {
            "key_code": "2"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad 3 key as 3",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_3"
           },
          "to": [
            {
            "key_code": "3"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad 4 key as 4",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_4"
           },
          "to": [
            {
            "key_code": "4"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad 5 key as 5",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_5"
           },
          "to": [
            {
            "key_code": "5"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad 6 key as 6",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_6"
           },
          "to": [
            {
            "key_code": "6"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad 7 key as 7",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_7"
           },
          "to": [
            {
            "key_code": "7"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad 8 key as 8",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_8"
           },
          "to": [
            {
            "key_code": "8"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad 9 key as 9",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_9"
           },
          "to": [
            {
            "key_code": "9"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad = key as =",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_equal_sign"
           },
          "to": [
            {
            "key_code": "equal_sign"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad / key as /",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_slash"
           },
          "to": [
            {
            "key_code": "slash"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad * key as *",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_asterisk"
           },
          "to": [
            {
            "key_code": "asterisk"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad - key as -",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_hyphen"
           },
          "to": [
            {
            "key_code": "hyphen"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad + key as +",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_plus"
           },
          "to": [
            {
            "key_code": "plus"
            }
           ],
           "type": "basic"
        }
       ]
    },
    {
      "description": "BEN: VMware Console Use Keypad ENTER key as ENTER",
      "manipulators": [
        {
          "conditions": [
            {
              "bundle_identifiers": [
                "^com\\.vmware\\.vmrc$",
                "^com\\.apple\\.Terminal$",
                "^com\\.googlecode\\.iterm2$"
              ],
              "type": "frontmost_application_if"
            }
           ],
          "from": {
              "key_code": "keypad_return_or_enter"
           },
          "to": [
            {
            "key_code": "return_or_enter"
            }
           ],
           "type": "basic"
        }
       ]
    }

  ]
}

Next I open Karabiner Elements.

Next I click on Complex Modifications and click on Add Rule

Scroll down and look for the “Map Keypad when using VMWare Console” Section.

To add them all, scroll down and you will see an Enable All button!

Now you will see them enabled on the next screen

Now when I open the Remote Console I am able to use the numeric keypad !!

Posted in Remote Console, VMWare | Leave a comment

Using AWK to print N lines up until the FIRST MATCH of a string and then exit

Often you are looking for a keyword within a log file but you need to print out X lines BEFORE the first match of a string, THEN exit the search.

There are many ways to skin a cat, and here are a few ways.

EXAMPLE 1:

In the following I am looking for 7 lines BEFORE the keyword phrase ‘Rolling back’

# cat logfile  | awk   'BEGIN{stopline=7} NR==1,/Rolling back/ {n=NR;l[n]=$0}END{last=n-stopline;for (i=last;i<=n;i++) {print l[i]}}'

Output:

2022-06-11 16:56:26 [pid 39154] LOG-THRIFTCLIENT-0002: [1] [tid 39154] Thrift transport exception type #1 (socket open() error: No route to host); failed to establish connection [addr=tt-peer-controller./port=9090].
Command killed: (signal 14) /usr/tintri/bin/fscmd -a 60 -h 'tt-peer-controller.' get-tuning-variable 'stasisDegradedModeTruncationTimeout'
Can't get 'stasisDegradedModeTruncationTimeout', error 142
Can't get timeouts, error 142
Upgrade completed; exit code 109
2022-06-11T16:57:22.166513-07:00 la-tintri01#b upgrade_pkg[30360]: Script /etc/sysconfig/tintri/post_upd/90-upgrade_fs exit code: 109
2022-06-11T16:57:22.167052-07:00 la-tintri01#b upgrade_pkg[30360]: Can not perform application upgrade, error 109
2022-06-11T16:57:22.167467-07:00 la-tintri01#b upgrade_pkg[30360]: Rolling back, state 9

EXAMPLE 2:

An easier way is to chain with tail; but who in the Linux world wants to do things the easy way right!?!?

#zcat logfile |awk 'NR==1,/Rolling back/' |tail -7

OUTPUT

2022-06-11 16:56:26 [pid 39154] LOG-THRIFTCLIENT-0002: [1] [tid 39154] Thrift transport exception type #1 (socket open() error: No route to host); failed to establish connection [addr=tt-peer-controller./port=9090].
Command killed: (signal 14) /usr/tintri/bin/fscmd -a 60 -h 'tt-peer-controller.' get-tuning-variable 'stasisDegradedModeTruncationTimeout'
Can't get 'stasisDegradedModeTruncationTimeout', error 142
Can't get timeouts, error 142
Upgrade completed; exit code 109
2022-06-11T16:57:22.166513-07:00 la-tintri01#b upgrade_pkg[30360]: Script /etc/sysconfig/tintri/post_upd/90-upgrade_fs exit code: 109
2022-06-11T16:57:22.167052-07:00 la-tintri01#b upgrade_pkg[30360]: Can not perform application upgrade, error 109
2022-06-11T16:57:22.167467-07:00 la-tintri01#b upgrade_pkg[30360]: Rolling back, state 9

EXAMPLE 3

Sometimes we need to search multiple files:

# awk   'NR==1,/Rolling back/' *.log |grep -H -B20 Rolling 

Or for GZ files

# zcat logfile*.gz|awk 'NR==1,/Rolling back/'

OR

# awk 'NR==1,/Rolling back/' <(gzip -dc logfile*.gz)
Posted in Command Line FU | Leave a comment

Ipmitool sel elist error: Timestamp Clock Sync | Asserted

The following error may be seen on a controller when viewing the ‘ipmitool sel elist’ output:

 275 | 06/01/2022 | 20:33:53 | Power Unit Pwr Unit Status | AC lost | Asserted
 276 | 06/01/2022 | 20:33:54 | Power Unit Pwr Unit Status | AC lost | Deasserted
 277 | 06/01/2022 | 20:34:05 | System Event BIOS Evt Sensor | Timestamp Clock Sync | Asserted
 278 | 06/01/2022 | 20:34:06 | System Event BIOS Evt Sensor | Timestamp Clock Sync | Asserted
 279 | 06/01/2022 | 20:34:45 | System Event BIOS Evt Sensor | OEM System boot event | Asserted
 27a | 06/01/2022 | 21:19:53 | Power Unit Pwr Unit Status | Power off/down | Asserted
 27b | 06/01/2022 | 21:19:59 | Power Unit Pwr Unit Status | Power off/down | Deasserted
 27c | 06/01/2022 | 21:20:12 | System Event BIOS Evt Sensor | Timestamp Clock Sync | Asserted
 27d | 06/01/2022 | 21:20:12 | System Event BIOS Evt Sensor | Timestamp Clock Sync | Asserted
 27e | 06/01/2022 | 21:20:51 | System Event BIOS Evt Sensor | OEM System boot event | Asserted
 27f | 06/01/2022 | 21:53:43 | Power Unit Pwr Unit Status | Power off/down | Asserted
 280 | 06/01/2022 | 21:53:49 | Power Unit Pwr Unit Status | Power off/down | Deasserted
 281 | 06/01/2022 | 21:54:02 | System Event BIOS Evt Sensor | Timestamp Clock Sync | Asserted
 282 | 06/01/2022 | 21:54:02 | System Event BIOS Evt Sensor | Timestamp Clock Sync | Asserted
 283 | 06/01/2022 | 21:54:41 | System Event BIOS Evt Sensor | OEM System boot event | Asserted

This message is one of two you will see when the system is powered on, or power cycled. 

Note in the above you also see “Power Unit Pwr Unit Status | Power off/down “

Posted in IPMI, Network Attached Storage (NAS) | Tagged , , | Leave a comment

Telnet to a port on a remote machine without ncat or telnet, or nmap

There are situations where you may be working on Linux based system, and telnet, ncat or nmap does not exist.

In Linux, you can route a test thru the protocol, destination IP address, and destination  port using the “/dev” linux ‘pseudo device’ 

The ‘telnet’ command we are all familiar with is essentially a wrapper for this procedure.

This can be done safely without impact to system operation.

# echo > /dev/tcp/10.10.154.121/10600 && echo "TCP Port 10600 is open"

The same works with UDP

 echo > /dev/udp/10.10.154.121/111 && echo "UDP Port 111 is open"

To test multiple TCP ports via for loop:

# for i in 88 111 135 139 445 464 3268 3269 ; do
echo > /dev/tcp/10.10.154.133/$i && echo "TCP Port $i is open"
done

Posted in Command Line FU, Networking | Tagged , , , , | Leave a comment

sed print only line AFTER string match

sed -n '/pattern/{n;p;}' infile

File

# cat infile
line 1
line 2
pattern
line 3
line 4

Example

# sed -n '/pattern/{n;p;}' infile
line 3
Posted in Command Line FU | Tagged , , | Leave a comment

Remove Leading and Trailing Whitespace using gsub in AWK

# echo "  this  test   "|awk '{gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}'
this  test
Posted in Command Line FU | Tagged | Leave a comment

Cut all characters after last match using SED

# echo "xxx/xxxx/xxxxx/yyy" | sed 's|\(.*\)/.*|\1|'
# echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|\(.*\)/.*|\1|'

Output

xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
Posted in Command Line FU | Tagged , , | Leave a comment

Increment a variable name within a BASH loop

#!/bin/bash
c=0
for i in a b; do
	log[$c]="$i"
	((c++))
done
for i in ${log[@]}; do
	echo $i
done

Example

# ./btest
a
b
Posted in Command Line FU | Tagged , , | Leave a comment

Enable CIFS/SMB Debug Logging

The following shows how you may enable additional debug logging on Linux for troubleshooting SMB related issues.

# modprobe cifs
# echo 'module cifs +p' > /sys/kernel/debug/dynamic_debug/control
# echo 'file fs/cifs/* +p' > /sys/kernel/debug/dynamic_debug/control
# echo 7 > /proc/fs/cifs/cifsFYI

Example log output:

# dmesg |tail -50
[75527.604137] CIFS: fs/cifs/connect.c: sndbuf 16384 rcvbuf 131072 rcvtimeo 0x1b58
[75527.606233] CIFS: fs/cifs/connect.c: cifs_get_tcp_session: next dns resolution scheduled for 600 seconds in the future
[75527.606246] CIFS: fs/cifs/connect.c: VFS: in cifs_get_smb_ses as Xid: 59 with uid: 0
[75527.606254] CIFS: fs/cifs/connect.c: Existing smb sess not found
[75527.606274] CIFS: fs/cifs/smb2pdu.c: Negotiate protocol
[75527.606298] CIFS: fs/cifs/transport.c: wait_for_free_credits: remove 1 credits total=0
[75527.606342] CIFS: fs/cifs/transport.c: Sending smb: smb_len=106
[75527.606530] CIFS: fs/cifs/connect.c: Demultiplex PID: 1177
[75527.606911] CIFS: fs/cifs/connect.c: RFC1002 header 0xe1
[75527.606940] CIFS: fs/cifs/smb2misc.c: SMB2 data length 97 offset 128
[75527.606949] CIFS: fs/cifs/smb2misc.c: SMB2 len 225
[75527.606963] CIFS: fs/cifs/smb2ops.c: smb2_add_credits: added 10 credits total=10
[75527.606976] CIFS: fs/cifs/transport.c: cifs_sync_mid_result: cmd=0 mid=0 state=4
[75527.606991] CIFS: fs/cifs/misc.c: Null buffer passed to cifs_small_buf_release
[75527.607001] CIFS: fs/cifs/smb2pdu.c: mode 0x1
[75527.607004] CIFS: fs/cifs/smb2pdu.c: negotiated smb3.0 dialect
[75527.607028] CIFS: fs/cifs/connect.c: Security Mode: 0x1 Capabilities: 0x300055 TimeAdjust: 0
[75527.607033] CIFS: fs/cifs/smb2pdu.c: Session Setup
[75527.607036] CIFS: fs/cifs/smb2pdu.c: sess setup type 3
[75527.607051] CIFS: fs/cifs/cifs_spnego.c: key description = ver=0x2;host=172.16.236.17;ip4=172.16.236.17;sec=krb5;uid=0x1388;creduid=0x0;user=bpatridge;pid=0x496
[75527.637196] CIFS: VFS: Verify user has a krb5 ticket and keyutils is installed
[75527.637225] CIFS: VFS: \\172.16.236.17 Send error in SessSetup = -126
[75527.637235] CIFS: fs/cifs/connect.c: VFS: leaving cifs_get_smb_ses (xid = 59) rc = -126
[75527.637245] CIFS: fs/cifs/dfs_cache.c: cache_refresh_path: search path: \172.16.236.17\tintri
[75527.637260] CIFS: fs/cifs/dfs_cache.c: get_dfs_referral: get an DFS referral for \172.16.236.17\tintri
[75527.637281] CIFS: fs/cifs/connect.c: VFS: leaving mount_put_conn
Posted in SAMBA/SMB/CIFS | Tagged , , , | Leave a comment