Advertisement
cz3dtc

Untitled

Jul 9th, 2021
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # this directory must exist to execute the script
  4. if [ -d /dev/disk/by-id/ ]; then :; else echo 'ERROR: /dev/disk/by-id/ does not exist'; exit 1; fi
  5.  
  6. # root user is necessary
  7. if [ $UID -gt 0 ]; then echo 'ERROR: You have to be root'; exit 1; fi
  8.  
  9. # list ALL partitions and exclude the SWAP ones
  10. declare -a SWAPS=( $(cat /proc/swaps | grep /dev/ | awk '{print$1}') )
  11. lsParts="ls -l /dev/disk/by-id/ | grep --regexp=-part[0-9] | awk '{sub(\"../../\",\"/dev/\");"
  12. for i in $(seq 0 $((${#SWAPS[@]} - 1))); do
  13. lsParts=${lsParts}' sub("'${SWAPS[$i]}'", "");'
  14. done
  15. lsParts=${lsParts}" print\$10}'"
  16. declare -a PARTITIONS=(`eval $lsParts`)
  17.  
  18. # format TEMP file
  19. for i in $(seq 0 $((${#PARTITIONS[@]} - 1))); do
  20. PARTITION=${PARTITIONS[$i]}
  21. if [ -n $PARTITION ]; then
  22. # first line, device name
  23. echo $PARTITION >> .temp.$$
  24. # mount info
  25. sudo dumpe2fs -h $PARTITION | grep 'Filesystem volume name' >> .temp.$$
  26. sudo dumpe2fs -h $PARTITION | grep 'Mount count' >> .temp.$$
  27. sudo dumpe2fs -h $PARTITION | grep 'Maximum mount count' >> .temp.$$
  28. sudo dumpe2fs -h $PARTITION | grep 'Last mount time' >> .temp.$$
  29. sudo dumpe2fs -h $PARTITION | grep 'Last checked' >> .temp.$$
  30. echo '-------------------------------' >> .temp.$$
  31. fi
  32. done
  33.  
  34. # show and delete TEMP file
  35. clear
  36. cat .temp.$$
  37. rm -f .temp.$$
  38.  
  39. # TUNE help
  40. echo
  41. echo 'HOWTO'
  42. echo -e "- Change Filesystem volume name:\n\tsudo tune2fs -L NewLabel /dev/hda1\n\tsudo e2label /dev/hda1 NewLabel"
  43. echo
  44. echo -e "- Change Maximum mount count:\n\tsudo tune2fs -c 50 /dev/hda1"
  45. echo
  46. echo -e "- Modify reserved space:\n\tsudo tune2fs -m 1 /dev/hda1"
  47. echo
  48.  
  49. exit 0
  50.  
  51.  
  52. Remember that you can call the script like this:
  53.  
  54. sudo bash ./scriptname.sh
  55.  
  56. But if you want to use it more than once, it's better to change the execute permissions and call it without the "bash" command:
  57.  
  58. chmod 755 ./scriptname.sh
  59. sudo ./scriptname.sh
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement