Guest User

Untitled

a guest
Apr 3rd, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. #Made by sixwheeledbeast, Estel, Malkavian, peterleinchen and vi_
  4.  
  5. ## Go root if not (Depends rootsh)
  6. #if [ `id -u` != 0 ] ; then
  7. # exec | sudo gainroot <<EOF
  8. #exec sh $0 $*
  9. #EOF
  10. # exit $?
  11. #fi
  12.  
  13. # Setup swap names for script
  14.  
  15. ## Swap 0 - Backup internal swap location
  16. swap0=/dev/mmcblk0p3
  17. echo $swap0
  18.  
  19. ## Swap 1 - First Main Swap Location
  20. swap1=/dev/mmcblk1p2
  21. echo $swap1
  22.  
  23. ## Swap 2 - Second Main Swap Location
  24. swap2=/dev/mmcblk1p3
  25. echo $swap2
  26.  
  27. ##Swap
  28. xswapon="/bin/busybox swapon"
  29. xswapoff="/bin/busybox swapoff"
  30.  
  31. # Setup notification banner
  32. banner(){
  33. o=org
  34. f=freedesktop
  35. n=Notifications
  36. run-standalone.sh dbus-send --type=method_call \
  37. --dest=$o.$f.$n /$o/$f/$n $o.$f.$n.SystemNoteInfoprint string:"$1"
  38. }
  39.  
  40. # Get and Print Current Swap Pre
  41. swap=`cat /proc/swaps | awk '/dev/ {print $1}'`
  42. echo $swap
  43. banner "$swap"
  44.  
  45. sleep 4
  46.  
  47. #Logic
  48. if [ "$swap" = "$swap1" ] ;
  49. then
  50. $xswapon $swap2
  51. $xswapoff $swap1
  52. elif [ "$swap" = "$swap2" ] ;
  53. then
  54. $xswapon $swap1
  55. $xswapoff $swap2
  56. elif [ "$swap" = "$swap0" ] ;
  57. then
  58. $xswapon $swap1
  59. $xswapoff $swap0
  60. sleep 5
  61. # Get and Print Current Swap Post
  62. swappost=`cat /proc/swaps | awk '/dev/ {print $1}'`
  63. banner "$swappost"
  64. else
  65. banner "Swap Switch Failed" && exit 1
  66. fi
  67. #End of Logic
  68.  
  69. sleep 2
  70. #Get current swap from /proc/swaps
  71. disk=$(cat /proc/swaps | awk '/dev/ {print $1}' | cut -d "/" -f 3)
  72. #Get blocks used since boot from /proc/diskstats
  73. ublocks=$(awk '{if ($3=="'"$disk"'") print $10}' /proc/diskstats)
  74. echo $ublocks ublocks
  75. #Multiply blocks by 512 to get used bytes
  76. ubytes=$(($ublocks*512))
  77. #Calculate used bytes into Kb, Mb and Gb
  78. echo $ubytes ubytes
  79. ukbytes=$(($ubytes/1024))
  80. umbytes=$(($ubytes/1024/1024))
  81. ugbytes=$(($ubytes/1024/1024/1024))
  82. echo $ukbytes ukbytes, $umbytes umbytes, $ugbytes ugbytes
  83. echo "$umbytes" > /tmp/flopswaplast && exit 1
Advertisement
Add Comment
Please, Sign In to add comment