Guest User

Untitled

a guest
Dec 4th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.73 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Enhanced version that preserves original nvme list formatting
  4. enhanced_nvme_list() {
  5.     # Get original nvme list output
  6.     local output
  7.     output=$(nvme list)
  8.  
  9.     if [ $? -ne 0 ] || [ -z "$output" ]; then
  10.         echo "Error: Failed to execute 'nvme list'"
  11.         exit 1
  12.     fi
  13.  
  14.     # Parse output line by line
  15.     IFS=$'\n' read -d '' -r -a lines <<< "$output"
  16.  
  17.     # Print header with additional columns
  18.     if [ ${#lines[@]} -ge 2 ]; then
  19.         echo "${lines[0]}  EUI64               NGUID"
  20.         echo "${lines[1]} -------------------- ---------------------------------"
  21.  
  22.         # Process data lines
  23.         for ((i=2; i<${#lines[@]}; i++)); do
  24.             line="${lines[i]}"
  25.             if [[ -n "$line" && ! "$line" =~ ^[[:space:]]*$ ]]; then
  26.                 # Extract device name (first field)
  27.                 dev=$(echo "$line" | awk '{print $1}')
  28.  
  29.                 # Get ns-descs info
  30.                 eui64="-"
  31.                 nguid="-"
  32.  
  33.                 if [ -e "$dev" ]; then
  34.                     ns_descs=$(nvme ns-descs "$dev" 2>/dev/null)
  35.                     if [ $? -eq 0 ]; then
  36.                         eui64=$(echo "$ns_descs" | awk '/eui64/ {print $3; exit}' | tr '[:lower:]' '[:upper:]')
  37.                         nguid=$(echo "$ns_descs" | awk '/nguid/ {print $3; exit}' | tr '[:lower:]' '[:upper:]')
  38.                     fi
  39.                 fi
  40.  
  41.                 # Default values if empty
  42.                 [ -z "$eui64" ] && eui64="-"
  43.                 [ -z "$nguid" ] && nguid="-"
  44.  
  45.                 # Print line with additional columns
  46.                 printf "%-60s %-20s %-20s\n" "$line" "$eui64" "$nguid"
  47.             fi
  48.         done
  49.     fi
  50. }
  51.  
  52. # Run the enhanced version
  53. enhanced_nvme_list
Advertisement
Add Comment
Please, Sign In to add comment