Guest User

Untitled

a guest
Oct 7th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.77 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Example output:
  4. #  /media/me/whatever
  5. #  /media/me/whatever2
  6. #
  7. lsblkOutput=$(lsblk -J -o MOUNTPOINT | \
  8.               jq -r '.blockdevices[] | select(.mountpoint != null) | .mountpoint | select(startswith("/media"))');
  9.  
  10. nameToShow=""
  11. deviceMountpoint=""
  12.  
  13. toConky=""
  14.  
  15. if [[ "$lsblkOutput" == "" ]]
  16. then
  17.   exit
  18. fi
  19.  
  20. # To array
  21. readarray -t devices <<<"$lsblkOutput"
  22. for device in "${devices[@]}"
  23. do
  24.     # Remove the path...
  25.     nameToShow=${device##*/}
  26.     # If the name has several words, only show the first one.
  27.     nameToShow=${nameToShow%\ *}
  28.     # In case the device has whitespaces in the name -> escape them
  29.     device=$(printf "%q" "$device")
  30.  
  31.     toConky="$toConky\${template3 $nameToShow $device}\n"
  32. done
  33.  
  34. printf '%b' "$toConky"
Add Comment
Please, Sign In to add comment