home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 August - Disc 1 / PCNET_CD_2006_08_1.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / savepuppyd < prev    next >
Encoding:
Text File  |  2006-06-17  |  3.1 KB  |  102 lines

  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler 2006 www.puppylinux.com
  3.  
  4. #saves current session, and/or monitors memory space.
  5. #run as a daemon, so will flush the tmpfs periodically, also if tmpfs getting full.
  6. #launched from /etc/rc.d/rc.local0, at low priority 19.
  7.  
  8. PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin"
  9.  
  10. PUPMODE=`cat /etc/rc.d/PUPMODE`
  11. [ $PUPMODE -eq 2 ] && exit #sanity check. full hd install.
  12.  
  13. PUPSAVE="`cat /etc/rc.d/PUPSAVE`"
  14. PMEDIA="`cat /etc/rc.d/PMEDIA`"
  15.  
  16. ##sanity check...
  17. #[ "`df -k | grep '/initrd/pup_rw' | grep "tmpfs"`" = "" ] && exit
  18.  
  19. sleep 600 #delay for 10 minutes.
  20.  
  21. #in some modes, monitor space only, do not save...
  22. MONITORONLY="yes"
  23. [ $PUPMODE -eq 3 ] && MONITORONLY="no"
  24. [ $PUPMODE -eq 7 ] && MONITORONLY="no"
  25. [ $PUPMODE -eq 13 ] && MONITORONLY="no"
  26.  
  27.  
  28. #check PMEDIA is usbflash or ideflash...
  29. LOOPDELAY=6
  30. SLEEPTIME=300 #save every 30 minutes.
  31. #if not a flash media, can save more frequently...
  32. [ "`echo -n "$PMEDIA" | grep "flash"`" = "" ] && SLEEPTIME=50 #save every 5 minutes.
  33. SAVESEC=`expr $LOOPDELAY \* $SLEEPTIME`
  34. SAVEMIN=`expr $SAVESEC \/ 60`
  35.  
  36. MSG1=""
  37. if [ "`df -k | grep '/initrd/pup_rw' | grep "tmpfs"`" = "" ];then
  38.  MSG1="You need to urgently make more space in the personal storage partition.
  39. In the case of a pup_save.3fs file, you could enlarge it."
  40. else
  41.  if [ "$MONITORONLY" = "no" ];then
  42.   MSG1="All working files are kept in ramdisk. This includes all new
  43. or modified files. Puppy saves all files to persistent storage
  44. every $SAVEMIN minutes, however the files are not flushed from the
  45. ramdisk. Flushing (at least in this version of Puppy), can
  46. only be achieved by rebooting Puppy."
  47.  fi
  48. fi
  49.  
  50. CNTSPD1=1
  51. while [ 1 ];do
  52.  
  53.  #also use free to find free ram, as df may not give true indication running out of ram.
  54.  REALUSED=`free | grep 'Total:' | tr -s " " | cut -f 3 -d " "`
  55.  REALTOTAL=`free | grep 'Total:' | tr -s " " | cut -f 2 -d " "`
  56.  USED100=`expr $REALUSED \* 100`
  57.  PERCENTRAM=`expr $USED100 \/ $REALTOTAL`
  58.  
  59.  #get percentage full...
  60.  PERCENTTMPFS=`df -k | grep '/initrd/pup_rw' | grep "tmpfs" | tr -s " " | cut -f 5 -d " " | cut -f 1 -d '%'`
  61.  PERCENTALL="$PERCENTTMPFS"
  62.  
  63.  [ $PERCENTRAM -gt $PERCENTTMPFS ] && PERCENTALL=$PERCENTRAM
  64.  
  65. # if [ $PERCENTALL -gt 97 ];then
  66. #  killall X
  67. #  sync
  68. #  exec /sbin/reboot &
  69. #  exit
  70. # fi
  71.  
  72. #v2.01 take this out for now, as we have the taskbar memory applet...
  73.  #if [ $PERCENTALL -gt 97 ];then
  74.  # sync
  75.  # if [ ! "`pidof X | tr "\n" "z"`" = "z" ];then
  76.  #  xmessage -center -display :0 -title "WARNING: memory nearly full" -bg '#ff8080' "Percentage of RAM that is used:              $PERCENTRAM
  77. #Percentage of personal storage that is used: $PERCENTTMPFS
  78. #
  79. #$MSG1
  80. #
  81. #The memory is now 97% full, which is getting critical."
  82.  # fi
  83.  # CNTSPD1=1
  84.  # sleep 300 #will keep warning every 5 minutes.
  85.  #fi
  86.  
  87. # #force saving of tmpfs to persistent storage...
  88. # [ $PERCENTTMPFS -gt 95 ] && CNTSPD1=$SLEEPTIME
  89.  
  90.  if [ $CNTSPD1 -ge $SLEEPTIME ];then #every 30 or 15 minutes.
  91.   CNTSPD1=1
  92.   sync
  93.   [ "$MONITORONLY" = "no" ] && /usr/sbin/snapmergepuppy /initrd/pup_ro1 /initrd/pup_rw
  94.   #...hm, should this be run at lowest priority? so as not to conflict.
  95.  fi
  96.  CNTSPD1=`expr $CNTSPD1 + 1`
  97.  sleep $LOOPDELAY
  98.  
  99. done
  100.  
  101. ###END###
  102.