home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #(c) Copyright Barry Kauler 2006 www.puppylinux.com
-
- #saves current session, and/or monitors memory space.
- #run as a daemon, so will flush the tmpfs periodically, also if tmpfs getting full.
- #launched from /etc/rc.d/rc.local0, at low priority 19.
-
- PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin"
-
- PUPMODE=`cat /etc/rc.d/PUPMODE`
- [ $PUPMODE -eq 2 ] && exit #sanity check. full hd install.
-
- PUPSAVE="`cat /etc/rc.d/PUPSAVE`"
- PMEDIA="`cat /etc/rc.d/PMEDIA`"
-
- ##sanity check...
- #[ "`df -k | grep '/initrd/pup_rw' | grep "tmpfs"`" = "" ] && exit
-
- sleep 600 #delay for 10 minutes.
-
- #in some modes, monitor space only, do not save...
- MONITORONLY="yes"
- [ $PUPMODE -eq 3 ] && MONITORONLY="no"
- [ $PUPMODE -eq 7 ] && MONITORONLY="no"
- [ $PUPMODE -eq 13 ] && MONITORONLY="no"
-
-
- #check PMEDIA is usbflash or ideflash...
- LOOPDELAY=6
- SLEEPTIME=300 #save every 30 minutes.
- #if not a flash media, can save more frequently...
- [ "`echo -n "$PMEDIA" | grep "flash"`" = "" ] && SLEEPTIME=50 #save every 5 minutes.
- SAVESEC=`expr $LOOPDELAY \* $SLEEPTIME`
- SAVEMIN=`expr $SAVESEC \/ 60`
-
- MSG1=""
- if [ "`df -k | grep '/initrd/pup_rw' | grep "tmpfs"`" = "" ];then
- MSG1="You need to urgently make more space in the personal storage partition.
- In the case of a pup_save.3fs file, you could enlarge it."
- else
- if [ "$MONITORONLY" = "no" ];then
- MSG1="All working files are kept in ramdisk. This includes all new
- or modified files. Puppy saves all files to persistent storage
- every $SAVEMIN minutes, however the files are not flushed from the
- ramdisk. Flushing (at least in this version of Puppy), can
- only be achieved by rebooting Puppy."
- fi
- fi
-
- CNTSPD1=1
- while [ 1 ];do
-
- #also use free to find free ram, as df may not give true indication running out of ram.
- REALUSED=`free | grep 'Total:' | tr -s " " | cut -f 3 -d " "`
- REALTOTAL=`free | grep 'Total:' | tr -s " " | cut -f 2 -d " "`
- USED100=`expr $REALUSED \* 100`
- PERCENTRAM=`expr $USED100 \/ $REALTOTAL`
-
- #get percentage full...
- PERCENTTMPFS=`df -k | grep '/initrd/pup_rw' | grep "tmpfs" | tr -s " " | cut -f 5 -d " " | cut -f 1 -d '%'`
- PERCENTALL="$PERCENTTMPFS"
-
- [ $PERCENTRAM -gt $PERCENTTMPFS ] && PERCENTALL=$PERCENTRAM
-
- # if [ $PERCENTALL -gt 97 ];then
- # killall X
- # sync
- # exec /sbin/reboot &
- # exit
- # fi
-
- #v2.01 take this out for now, as we have the taskbar memory applet...
- #if [ $PERCENTALL -gt 97 ];then
- # sync
- # if [ ! "`pidof X | tr "\n" "z"`" = "z" ];then
- # xmessage -center -display :0 -title "WARNING: memory nearly full" -bg '#ff8080' "Percentage of RAM that is used: $PERCENTRAM
- #Percentage of personal storage that is used: $PERCENTTMPFS
- #
- #$MSG1
- #
- #The memory is now 97% full, which is getting critical."
- # fi
- # CNTSPD1=1
- # sleep 300 #will keep warning every 5 minutes.
- #fi
-
- # #force saving of tmpfs to persistent storage...
- # [ $PERCENTTMPFS -gt 95 ] && CNTSPD1=$SLEEPTIME
-
- if [ $CNTSPD1 -ge $SLEEPTIME ];then #every 30 or 15 minutes.
- CNTSPD1=1
- sync
- [ "$MONITORONLY" = "no" ] && /usr/sbin/snapmergepuppy /initrd/pup_ro1 /initrd/pup_rw
- #...hm, should this be run at lowest priority? so as not to conflict.
- fi
- CNTSPD1=`expr $CNTSPD1 + 1`
- sleep $LOOPDELAY
-
- done
-
- ###END###
-