############### ### ALIASES ### #################################################################################################### ### BASE ### alias @profile='. ~/.profile' alias @aliases='source <(curl -sL a.aronmgv.com)' ### OOB Serial ### alias @com-caradhras='socat -,raw,echo=0,escape=0x1d tcp:192.168.255.241:4000' ### MAN ### alias @man-linux='curl -s https://static.aronmgv.com/man/linux' alias @man-tmux='curl -s https://static.aronmgv.com/man/tmux' alias @man-docker='curl -s https://static.aronmgv.com/man/docker' alias @man-git='curl -s https://static.aronmgv.com/man/git' alias @man-vim='curl -s https://static.aronmgv.com/man/vim' alias @man-postgres='curl -s https://static.aronmgv.com/man/postgres' ### SERVICES ### #wsdd alias @stop-wsdd='systemctl stop wsdd.service' alias @start-wsdd='systemctl start wsdd.service' alias @status-wsdd='systemctl status wsdd.service' alias @restart-wsdd='systemctl restart wsdd.service' #samba alias @stop-samba='systemctl stop smb.service' alias @start-samba='systemctl start smb.service' alias @status-samba='systemctl status smb.service' alias @restart-samba='systemctl restart smb.service' #network file share alias @stop-nfs='systemctl stop nfs-kernel-server.service' alias @start-nfs='systemctl start nfs-kernel-server.service' alias @status-nfs='systemctl status nfs-kernel-server.service' alias @restart-nfs='systemctl restart nfs-kernel-server.service' #docker alias @stop-docker='systemctl stop docker.service docker.socket' alias @start-docker='systemctl start docker.service docker.socket' alias @status-docker='systemctl status docker.service docker.socket' alias @restart-docker='systemctl restart docker.service docker.socket' ### SYSTEM ### alias sctl='systemctl' alias apt-get-key='apt-key adv --keyserver keyserver.ubuntu.com --recv-keys' #alias rs='rsync -s -azAX --info=progress2' #alias rsc='rsync -s -azncAX --info=progress2' #alias rsm='rsync -s -azAX --remove-source-files --delete --info=progress2' #alias rsd='rsync -s -azAX --delete --info=progress2' alias @df='df -hT' alias @dff='df -hT | grep -v docker' alias @dupwd='du -h --max-depth=1 | sort -hr' alias @dubpwd='du -h --max-depth=1 --block-size=1 | sort -hr' alias @duapwd='du -ah --max-depth=1 | sort -hr' alias @dubapwd='du -ah --max-depth=1 --block-size=1 | sort -hr' alias @fdisk-size='fdisk -l | grep "Disk /"' alias @hdparm='hdparm -I /dev/sd?|grep -E "Number|/dev"' alias @hddinfo='lsblk --nodeps -o name,model,serial,size' alias @mdadm-assemble='mdadm --assemble --scan' alias @mdadm-detail='mdadm --detail /dev/md0' alias @mdadm-save='mdadm --detail --scan --verbose >> /etc/mdadm/mdadm.conf' alias @mdstat='cat /proc/mdstat' alias tmuxl='tmux ls' alias tmuxa='tmux attach -d -t' alias tmuxk='tmux kill-session -t' alias @tmux='tmux' alias @tmux-ls='tmux ls' alias @tmux-attach='tmux attach -d -t' alias @tmux-kill='tmux kill-session -t' alias @xauth-list='xauth list' alias @xauth-add_macgyver='xauth add $(xauth -f ~macgyver/.Xauthority list|tail -1)' alias @users='cut -d: -f1 /etc/passwd' alias @hugepages='cat /proc/meminfo | grep Huge' alias @lspci-nvidia='lspci -nn | grep -i nvidia' alias @vfio-nvidia='dmesg | grep -i vfio' alias @iommu='dmesg | grep -E "DMAR|IOMMU"' ### BACKUPS ### alias @backup-zeroed='dd if=/dev/zero of=/tmp/delete.me bs=8M; rm -f /tmp/delete.me' alias @backup-system='dd if=/dev/main/root conv=sync,noerror bs=64K | gzip -c | dd of=/lvm/raid/private/backups/system/debian`cat /etc/debian_version | cut -c1-2`/root@`date +"%Y-%m-%d.%H-%M"`.img.gz' #alias @backup-system-rsync='rsync --info=progress2 -aAX --delete --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lvm/*,/lost+found,/.cache,swapfile,/hugepages}' alias @backup-system-rsync='rsync --info=progress2 -aAX --delete --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lvm/*,/lost+found,/.cache,swapfile,/hugepages} / /lvm/raid/private/backups/system/raw' ### GENERIC COMMANDS ### alias @netstat='netstat -tupanve' alias @netstat-rn='netstat -rn' #alias @hddtemp='hddtemp -q /dev/sd[a-z] | grep "/dev/sd[a-z]\:\|[0-9][0-9]°C"' alias @sensors='sensors && @hddtemps' alias @iptables='iptables -vnL --line-numbers' alias @iptables-save='iptables-save > /etc/iptables/rules.v4' alias @iptables-restore='iptables-restore < /etc/iptables/rules.v4' alias @iptables-allin='iptables -P INPUT ACCEPT' alias @iptables-dropin='iptables -P INPUT DROP' alias @iptables-clear-all='iptables -P INPUT ACCEPT && iptables -P FORWARD ACCEPT && iptables -P OUTPUT ACCEPT && iptables -t nat -F && iptables -t mangle -F && iptables -F && iptables -X' alias @ip6tables='ip6tables -vnL --line-numbers' alias @ip6tables-save='ip6tables-save > /etc/iptables/rules.v6' alias @ip6tables-restore='ip6tables-restore < /etc/iptables/rules.v6' alias @ip6tables-allin='ip6tables -P INPUT ACCEPT' alias @ip6tables-dropin='ip6tables -P INPUT DROP' alias @ip6tables-clear-all='ip6tables -P INPUT ACCEPT && ip6tables -P FORWARD ACCEPT && ip6tables -P OUTPUT ACCEPT && ip6tables -t nat -F && ip6tables -t mangle -F && ip6tables -F && ip6tables -X' ### LVM Partition Management ### alias @lvm-pvs='pvs' alias @lvm-vgs='vgs' alias @lvm-lvs='lvs' ### ARCHIVE COMMANDS ### alias @tar-x='tar -xvf' alias @targz-x='tar -xzvf' alias @tarbz-x='tar -xjvf' alias @tar-c='tar -cvf' alias @targz-c='tar -czvf' alias @tarbz-c='tar -cjvf' ### RSYNC COMMANDS ### alias @rsync-recursive='rsync --info=progress2 -rlp' alias @rsync-archive='rsync --info=progress2 -aAX' alias @rsync-compare='rsync -avnc' ### GIT ### alias @git-config-list='git config --list' alias @git-config-local-add='git config --local --add ' alias @git-config-local-unset='git config --local --unset ' alias @git-config-global-add='git config --global --add ' alias @git-config-global-unset='git config --global --unset ' #alias @git-log='git log --pretty=format:"%h %s" --graph' alias @git-log='git log --graph --decorate --pretty=oneline --abbrev-commit' ### WAKE ON LAN ### alias @wake-caradhras='wakeonlan -i 192.168.255.254 b4:2e:99:a0:7c:8e' alias @wake-edoras='wakeonlan -i 192.168.255.254 70:70:fc:08:2a:9a' alias @wake-rhun='wakeonlan -i 192.168.254.254 e8:9c:25:78:34:ca' ### DOCKER ### alias de='@docker-exec' alias der='@docker-exec-root' alias ds='@docker-ps' alias dr='@docker-restart' alias di='@docker-inspect' alias dk='@docker-kill' alias dl='@docker-logs' alias dpa='@docker-prune-system-all' alias @docker-ps='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Size}}\t\t{{.Ports}}" | awk '"'"'NR<2{print $0;next}{print $0 | "sort --key=2"}'"'"'' alias @docker-images='docker images' alias @docker-images-a='docker images -a' alias @docker-exec='docker exec -it' alias @docker-exec-root='docker exec -it --user root' alias @docker-restart='docker restart' alias @docker-inspect='docker inspect' alias @docker-kill='docker kill' alias @docker-logs='docker logs' alias @docker-prune-network='docker network prune' alias @docker-prune-container='docker container prune' alias @docker-prune-image='docker image prune' alias @docker-prune-image-all='docker image prune --all' alias @docker-prune-volume='docker volume prune' alias @docker-prune-volume-all='docker volume prune --all' alias @docker-prune-system='docker system prune' alias @docker-prune-system-all='docker system prune --all --volumes' ### DOCKER COMPOSE ### alias dc='docker compose' alias dcs='docker compose ps' alias dcu='docker compose up -d' alias dcd='docker compose down' alias dcl='docker compose logs -f' alias dcll='docker compose logs -f --tail 100' alias dclll='docker compose logs -f --tail 1000' alias dcllll='docker compose logs -f --tail 10000' alias dcp='docker compose pull' alias dcb='docker compose build' alias dcrm='docker compose rm -fsv' alias dcrma='docker compose down -v --rmi all --remove-orphans' alias dcus='dcu && dcs' alias dcul='dcu && dcl' alias dcr='dcd && dcu' alias dcrs='dcd && dcu && dcs' alias dcrl='dcd && dcu && dcl' alias dcg='dcp && dcr' alias dcgs='dcg && dcs' alias dcgl='dcg && dcl' alias dcm='dcb && dcr' alias dcms='dcm && dcs' alias dcml='dcm && dcl' ### TUNNELING ### alias @tunnel-proxy='ssh -L 3128:localhost:46886 homie@aronmgv.com' ### OTHERS ### alias @traefik-refresh='touch /docker/+traefik/traefik/middleware/main.yml' ################# ### FUNCTIONS ### #################################################################################################### function dcuf { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: dcuf " return 1 else docker compose -f $1 up -d fi } function dcdf { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: dcdf " return 1 else docker compose -f $1 down fi } function dcrf { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: dcrf " return 1 else dcdf $1 && dcuf $1 fi } function dcsf { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: dcsf " return 1 else docker compose -f $1 ps fi } function dcgf { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: dcgf " return 1 else docker compose -f $1 pull && dcrf $1 fi } function dcuc { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: dcuc " return 1 else docker compose up -d $1 fi } function dcdc { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: dcdc " return 1 else docker compose rm -fsv $1 fi } function dcrc { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: dcrc " return 1 else docker compose rm -fsv $1 && docker compose up -d $1 fi } function dcrcl { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: dcrc " return 1 else docker compose rm -fsv $1 && docker compose up -d $1 && docker compose logs -f $1 fi } function dcgc { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: dcrc " return 1 else docker compose pull $1 && docker compose rm -fsv $1 && docker compose up -d $1 fi } function dcgcl { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: dcrc " return 1 else docker compose pull $1 && docker compose rm -fsv $1 && docker compose up -d $1 && docker compose logs -f $1 fi } # ============================================================================= # Remote rsync helper functions # ----------------------------------------------------------------------------- # Same structure as before — each function spells out its own rsync lines. # The only change: an optional "-fast" flag as the FIRST argument, which # swaps the flag set for fast-LAN transfers: # # normal : -azvP (-z compresses in transit, delta-transfer on) # -fast : -avP --whole-file (no compression, no delta-transfer) # # Why: on a fast LAN, -z burns CPU compressing data that's often already # compressed (video, images, archives), and the delta-transfer algorithm # spends CPU + disk I/O checksumming blocks to avoid resending them — which # only pays off on slow links. Dropping both is usually faster over gigabit. # # Flag order: "-fast" must come first, then "-p PORT". So: # rsr -fast -p 2222 /src/ host:/dst/ works # rsr -p 2222 -fast /src/ host:/dst/ does NOT (matches original design, # where -p also had to be first) # ============================================================================= # Usage examples # ----------------------------------------------------------------------------- # rsr /src/ host:/dst/ normal sync, compression on # rsr -fast /src/ host:/dst/ LAN sync: no -z, --whole-file # rsr -p 2222 /src/ host:/dst/ custom SSH port # rsr -fast -p 2222 /src/ host:/dst/ both (-fast must be first) # # rscr /src/ host:/dst/ preview differences, change nothing # rsmr -fast /src/ host:/dst/ move data across, fast LAN settings # rsdr /src/ host:/dst/ mirror, deleting extras on destination # ============================================================================= function rs { rsync -s -azAX --info=progress2 "$@" } function rsv { rsync -s -azAX -v "$@" } function rsc { rsync -s -azncAX --info=progress2 "$@" } function rscv { rsync -s -azncAX -v "$@" } function rsm { rsync -s -azAX --remove-source-files --delete --info=progress2 "$@" } function rsmv { rsync -s -azAX --remove-source-files --delete -v "$@" } function rsd { rsync -s -azAX --delete --info=progress2 "$@" } function rsdv { rsync -s -azAX --delete -v "$@" } # ----------------------------------------------------------------------------- # remote sync - won't delete extra files on destination # ----------------------------------------------------------------------------- function rsr { if [ "$1" = '-fast' ]; then # -fast given: shift the window past it, so -p (if any) is now $2 if [ "$2" = '-p' ]; then rsync -s -avP --whole-file --exclude='*.skip/' -e "ssh -p $3" "${@:4}" else rsync -s -avP --whole-file --exclude='*.skip/' -e "ssh" "${@:2}" fi elif [ "$1" = '-p' ]; then rsync -s -azvP --exclude='*.skip/' -e "ssh -p $2" "${@:3}" else rsync -s -azvP --exclude='*.skip/' -e "ssh" "${@:1}" fi } # ----------------------------------------------------------------------------- # remote sync - compare # -n dry run: show what would happen, change nothing # -c compare by checksum instead of size+mtime (slower, but catches files # that differ despite identical size/timestamp) # ----------------------------------------------------------------------------- function rscr { if [ "$1" = '-fast' ]; then if [ "$2" = '-p' ]; then rsync -s -avncP --whole-file --exclude='*.skip/' -e "ssh -p $3" "${@:4}" else rsync -s -avncP --whole-file --exclude='*.skip/' -e "ssh" "${@:2}" fi elif [ "$1" = '-p' ]; then rsync -s -azvncP --exclude='*.skip/' -e "ssh -p $2" "${@:3}" else rsync -s -azvncP --exclude='*.skip/' -e "ssh" "${@:1}" fi } # ----------------------------------------------------------------------------- # remote sync - will move all folders and files from source to destination # --remove-source-files delete each source file once transferred OK # --delete remove destination files not present in source # Note: --remove-source-files only removes FILES, never directories — empty # source dirs are left behind. Clean up afterwards if wanted: # find /source/path -type d -empty -delete # ----------------------------------------------------------------------------- function rsmr { if [ "$1" = '-fast' ]; then if [ "$2" = '-p' ]; then rsync -s -avP --whole-file --exclude='*.skip/' --remove-source-files -e "ssh -p $3" "${@:4}" else rsync -s -avP --whole-file --exclude='*.skip/' --remove-source-files -e "ssh" "${@:2}" fi elif [ "$1" = '-p' ]; then rsync -s -azvP --exclude='*.skip/' --remove-source-files -e "ssh -p $2" "${@:3}" else rsync -s -azvP --exclude='*.skip/' --remove-source-files -e "ssh" "${@:1}" fi } # ----------------------------------------------------------------------------- # remote rsync - will delete redundant files which are not present in source # ----------------------------------------------------------------------------- function rsdr { if [ "$1" = '-fast' ]; then if [ "$2" = '-p' ]; then rsync -s -avP --whole-file --exclude='*.skip/' --delete -e "ssh -p $3" "${@:4}" else rsync -s -avP --whole-file --exclude='*.skip/' --delete -e "ssh" "${@:2}" fi elif [ "$1" = '-p' ]; then rsync -s -azvP --exclude='*.skip/' --delete -e "ssh -p $2" "${@:3}" else rsync -s -azvP --exclude='*.skip/' --delete -e "ssh" "${@:1}" fi } function @du { if [ $# -le 1 ]; then if [ -z "$1" ]; then du -h --max-depth=1 | sort -hr else du $1 -h --max-depth=1 | sort -hr fi else echo "Usage: @du [location to disple disk usage for..]" return 1 fi } function @dub { if [ $# -le 1 ]; then if [ -z "$1" ]; then du -h --max-depth=1 --block-size=1 | sort -hr else du $1 -h --max-depth=1 --block-size=1 | sort -hr fi else echo "Usage: @dub [location to disple disk usage for..]" return 1 fi } function @dua { if [ $# -le 1 ]; then if [ -z "$1" ]; then du -ah --max-depth=1 | sort -hr else du $1 -ah --max-depth=1 | sort -hr fi else echo "Usage: @dua [location to disple disk usage for..]" return 1 fi } function @duba { if [ $# -le 1 ]; then if [ -z "$1" ]; then du -ah --max-depth=1 --block-size=1 | sort -hr else du $1 -ah --max-depth=1 --block-size=1 | sort -hr fi else echo "Usage: @duba [location to disple disk usage for..]" return 1 fi } function watcha { watch $(alias "$@" | cut -d\' -f2) } function @subdomain { if [ $# -lt 1 ]; then echo "Usage: @traefik-find " return 1 fi grep -r --include='*.yml' --include='*.yaml' "$1" /docker/+traefik/traefik/middleware/ } ############### ### SCRIPTS ### #################################################################################################### ### HDD INFO+TEMP ### # Function to check if a drive exists and retrieve its temperature get_drive_temperature() { local drive="$1" local info info="$(sudo smartctl -a "$drive" 2>/dev/null)" local temp="" # For SATA/SAS drives (HDD/SSD) temp=$(echo "$info" | grep '194 Temp' | awk '{print $10}') if [[ -z $temp ]]; then temp=$(echo "$info" | grep '190 Airflow' | awk '{print $10}') fi if [[ -z $temp ]]; then temp=$(echo "$info" | grep 'Temperature Sensor 1:' | awk '{print $4}') fi if [[ -z $temp ]]; then temp=$(echo "$info" | grep 'Current Drive Temperature:' | awk '{print $4}') fi if [[ -z $temp ]]; then temp=$(echo "$info" | grep -m1 'Temperature:' | awk '{print $2}' | sed 's/[^0-9]*//g') fi # For NVMe drives if [[ -z $temp ]]; then temp=$(echo "$info" | grep -m1 'Temperature:' | awk '{print $2}' | sed 's/[^0-9]*//g') fi if [[ -z $temp ]]; then temp=$(echo "$info" | grep -m1 'Composite Temperature:' | awk '{print $3}' | sed 's/[^0-9]*//g') fi if [[ -z $temp ]]; then temp=$(echo "$info" | grep -m1 'Temperature Sensor 1:' | awk '{print $4}' | sed 's/[^0-9]*//g') fi echo "$temp" } # Function to get Power_On_Hours and convert to days and years get_drive_hours_days_years() { local drive="$1" local info info="$(sudo smartctl -A "$drive" 2>/dev/null)" local hours="" hours=$(echo "$info" | awk '/Power_On_Hours/ {print $NF}') if [[ -z "$hours" ]]; then hours=$(echo "$info" | grep -m1 'Power On Hours:' | awk '{print $4}') fi if [[ -z "$hours" ]]; then echo "N/A" return fi # Remove comma if present in hours value hours=$(echo "$hours" | tr -d ',') local days years days=$(awk "BEGIN {printf \"%.2f\", $hours/24}") years=$(awk "BEGIN {printf \"%.2f\", $hours/24/365.25}") echo "${hours} (${days}) (${years})" } # Function to get a SMART attribute value get_smart_attr() { local drive="$1" local attr="$2" local info info="$(sudo smartctl -A "$drive" 2>/dev/null)" # Try by attribute name first, then by column echo "$info" | awk -v attr="$attr" '$2==attr || $1==attr {print $10}' | head -n1 } # Function to get SMART overall health assessment get_smart_health() { local drive="$1" local info info="$(sudo smartctl -H "$drive" 2>/dev/null)" local health health=$(echo "$info" | grep -E "SMART overall-health|SMART Health Status:" | awk -F': ' '{print $2}') [[ -z "$health" ]] && health="N/A" echo "$health" } # Function to print drive info including Power_On_Hours (Days) (Years) and Health list_drive_info_temps() { local drives=() for drive in /dev/sd? /dev/nvme*n1; do if [ -e "$drive" ]; then drives+=("$drive") fi done # Set column widths for proper alignment and header fit local name_width=12 local model_width=30 local serial_width=24 local size_width=12 local temp_width=8 local hours_width=28 # Increased width for new column local health_width=8 # Print header (left-aligned, matching widths) printf "%-${name_width}s %-${model_width}s %-${serial_width}s %-${size_width}s %-${temp_width}s %-${hours_width}s %-${health_width}s\n" \ "Name" "Model" "Serial" "Size" "Temp" "Hours (Days) (Years)" "Health" for drive in "${drives[@]}"; do name=$(basename "$drive") size=$(lsblk -ndo SIZE "$drive" | xargs) # Extract Model and Serial as their own lines, trimming whitespace model=$(sudo smartctl -i "$drive" 2>/dev/null | grep -m1 -E 'Device Model:|Model Number:|Model:' | sed 's/^[^:]*: *//' | xargs) if [[ -z "$model" ]]; then model=$(lsblk -ndo MODEL "$drive" | xargs) fi serial=$(sudo smartctl -i "$drive" 2>/dev/null | grep -m1 -E 'Serial Number:|Serial:' | sed 's/^[^:]*: *//' | xargs) if [[ -z "$serial" ]]; then serial=$(lsblk -ndo SERIAL "$drive" | xargs) fi temp=$(get_drive_temperature "$drive") if [[ -z "$temp" ]]; then temp="N/A" else temp="${temp}°C" fi hoursdaysyears=$(get_drive_hours_days_years "$drive") if [[ -z "$hoursdaysyears" ]]; then hoursdaysyears="N/A" fi health=$(get_smart_health "$drive") # Truncate fields to column width for alignment, add 1 extra space before hours column value printf "%-${name_width}s %-${model_width}s %-${serial_width}s %-${size_width}s %-${temp_width}s %-${hours_width}s %-${health_width}s\n" \ "$name" "$model" "$serial" "$size" "$temp" " $hoursdaysyears" " $health" done } # Function to print extended drive info including SMART attributes and health list_drive_full_smart_info() { local drives=() for drive in /dev/sd? /dev/nvme*n1; do if [ -e "$drive" ]; then drives+=("$drive") fi done # Set column widths for proper alignment and header fit local name_width=12 local model_width=30 local serial_width=24 local size_width=12 local temp_width=8 local hours_width=28 # Increased width for new column local attr_width=12 local health_width=8 # Print header printf "%-${name_width}s %-${model_width}s %-${serial_width}s %-${size_width}s %-${temp_width}s %-${hours_width}s %-${attr_width}s %-${attr_width}s %-${attr_width}s %-${attr_width}s %-${attr_width}s %-${attr_width}s %-${attr_width}s %-${health_width}s\n" \ "Name" "Model" "Serial" "Size" "Temp" "Hours (Days) (Years)" "Realloc" "Pend" "Uncorr" "SeekErr" "SpinRet" "StartStop" "CmdTO" "Health" for drive in "${drives[@]}"; do name=$(basename "$drive") size=$(lsblk -ndo SIZE "$drive" | xargs) # Extract Model and Serial as their own lines, trimming whitespace model=$(sudo smartctl -i "$drive" 2>/dev/null | grep -m1 -E 'Device Model:|Model Number:|Model:' | sed 's/^[^:]*: *//' | xargs) if [[ -z "$model" ]]; then model=$(lsblk -ndo MODEL "$drive" | xargs) fi serial=$(sudo smartctl -i "$drive" 2>/dev/null | grep -m1 -E 'Serial Number:|Serial:' | sed 's/^[^:]*: *//' | xargs) if [[ -z "$serial" ]]; then serial=$(lsblk -ndo SERIAL "$drive" | xargs) fi temp=$(get_drive_temperature "$drive") if [[ -z "$temp" ]]; then temp="N/A" else temp="${temp}°C" fi hoursdaysyears=$(get_drive_hours_days_years "$drive") if [[ -z "$hoursdaysyears" ]]; then hoursdaysyears="N/A" fi # SMART attributes realloc=$(get_smart_attr "$drive" "Reallocated_Sector_Ct") [[ -z "$realloc" ]] && realloc="N/A" pend=$(get_smart_attr "$drive" "Current_Pending_Sector") [[ -z "$pend" ]] && pend="N/A" uncorr=$(get_smart_attr "$drive" "Offline_Uncorrectable") [[ -z "$uncorr" ]] && uncorr="N/A" seekerr=$(get_smart_attr "$drive" "Seek_Error_Rate") [[ -z "$seekerr" ]] && seekerr="N/A" spinret=$(get_smart_attr "$drive" "Spin_Retry_Count") [[ -z "$spinret" ]] && spinret="N/A" startstop=$(get_smart_attr "$drive" "Start_Stop_Count") [[ -z "$startstop" ]] && startstop="N/A" cmdto=$(get_smart_attr "$drive" "Command_Timeout") [[ -z "$cmdto" ]] && cmdto="N/A" health=$(get_smart_health "$drive") # Print each row, add extra space before hours column value printf "%-${name_width}s %-${model_width}s %-${serial_width}s %-${size_width}s %-${temp_width}s %-${hours_width}s %-${attr_width}s %-${attr_width}s %-${attr_width}s %-${attr_width}s %-${attr_width}s %-${attr_width}s %-${attr_width}s %-${health_width}s\n" \ "$name" "$model" "$serial" "$size" "$temp" " $hoursdaysyears" " $realloc" " $pend" " $uncorr" " $seekerr" " $spinret" " $startstop" " $cmdto" " $health" done } # Function to print just drive temperatures for both SATA/SAS and NVMe, with neat alignment list_drive_temps() { local drives=() for drive in /dev/sd? /dev/nvme*n1; do if [ -e "$drive" ]; then drives+=("$drive") fi done # Find the length of the longest device name local maxlen=0 for drive in "${drives[@]}"; do [ ${#drive} -gt $maxlen ] && maxlen=${#drive} done # Print header printf "%-${maxlen}s %s\n" "Device" "Temperature" # Print each drive aligned for drive in "${drives[@]}"; do temperature=$(get_drive_temperature "$drive") if [[ -z "$temperature" ]]; then temperature="N/A" else temperature="${temperature}°C" fi printf "%-${maxlen}s %s\n" "$drive" "$temperature" done } alias @hddtemps='list_drive_temps' alias @hdds='list_drive_info_temps' alias @hddinfo='list_drive_full_smart_info' ############################# ### AUTO-COMPLETE ALIASES ### #################################################################################################### function autocompleteAliases { aliases=$(alias | grep = | awk '{print $2}'| awk -F '=' '{print $1}') for i in ${aliases[@]}; do complete -F _complete_alias $i; done } autocompleteAliases ####################################################################################################