个人工具
登录
查看“UbuntuHelp:EmptyDiskSpace”的源代码 - Ubuntu中文
UbuntuHelp
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“UbuntuHelp:EmptyDiskSpace”的源代码
来自Ubuntu中文
←
UbuntuHelp:EmptyDiskSpace
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{From|https://help.ubuntu.com/community/EmptyDiskSpace}} {{Languages|UbuntuHelp:EmptyDiskSpace}} <<Include(Tag/StyleCleanup)>> == Introduction == Did you ever wasted time investgating software problems or application crashes only to find out that it was caused by a full hard disk? The following simpel script warns if your hard disk runs out of available disk space. == Installation == 1. Open a text editor with sudo to create the file /usr/local/bin/monitordiskspace. <pre><nowiki> gksudo gedit /usr/local/bin/monitordiskspace </nowiki></pre> 2. Copy the following script into the text editor: <pre><nowiki> #!/bin/sh # This script is an adapted from Hans Zoebelein's (zocki@goldfish.cube.net) # script found at http://www.faqs.org/docs/Linux-HOWTO/Tips-HOWTO.html#ss2.3 # # Shoot and forget: Put 'check_hdspace &' in rc.local. # Checks for available space on devices every $SLEEPTIME sec. # You even might check your floppies or tape drives. :) # If available space is below $MINFREE (kb), it will echo a warning # and send one mail for each triggering device to $MAIL_TO_ME. # If there is more available space than trigger limit again, # mail action is also armed again. # # TODO: # Detect partitions automatically at startup # Different $MINFREE for each device. # Free /*tmp dirs securely from old junk stuff if no more free space etc. # Check https://wiki.ubuntu.com/FullFilesystemSanityGutsy and # https://wiki.ubuntu.com/HardyFullDiskHandling for the whole picture. DEVICES='/dev/sda2' # device; your put disks here, separated by blanks MINFREE=20480 # kb; below this do warning SLEEPTIME=10 # sec; sleep between checks # ------- no changes needed below this line (hopefully :) ------- MINMB=0 ISFREE=0 MAILED="" MINMB=`expr $MINFREE / 1024` # yep, we are strict :) while [ 1 ]; do DF="`/bin/df`" for DEVICE in $DEVICES ; do ISFREE=`echo $DF | sed s#.\*$DEVICE" "\*[0-9]\*" "\*[0-9]\*" "\*## | sed s#" ".\*##` if [ $ISFREE -le $MINFREE ] ; then ISMB=`expr $ISFREE / 1024` if [ -z "`echo $MAILED | grep -w $DEVICE`" ] ; then MAILEDH="$MAILED $DEVICE" MAILED=$MAILEDH if $( zenity --question --text "WARNING: $DEVICE only $ISMB mb free. (Trigger is set to $MINMB mb) Do you want to empty trash and erase downloaded software archive files?" ) then rm -r ~/.local/share/Trash/info/* rm -r ~/.local/share/Trash/files/* gksudo apt-get clean # put further action here like cleaning # up */tmp dirs... fi fi elif [ -n "`echo $MAILED | grep -w $DEVICE`" ] ; then # Remove mailed marker if enough disk space # again. So we are ready for new mailing action. MAILEDH="`echo $MAILED | sed s#$DEVICE##`" MAILED=$MAILEDH fi done sleep $SLEEPTIME done </nowiki></pre> 3. Adapt the variable "DEVICES" to include your relevant devices. It should include your root and your home partition (if differ). Use the command "mount" to get a list of your devices. Optional: Adapt "MINFREE" to your requirements. 4. Save the file and close the text editor. 5. The script should be started automatically at each system start resp. login. Therefore we need to select System -> Preferences -> Sessions. Select "add" and write the name "monitor disk space" and the command "/usr/local/bin/monitordiskspace" while the comment can be left blank. Close the dialog with "OK". Note: This needs to be configured for every user who should be informed in case of empty disk space. 6. Close the current session and login to Ubuntu again. The script will be executed silently in the background. If the disk space runs full the current user is warned and prompted to empty her trash bin and erase downloded software packages. == See Also == For the big picture see the following links. * https://wiki.ubuntu.com/FullFilesystemSanityGutsy * https://wiki.ubuntu.com/HardyFullDiskHandling * A similar script can be found [http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html here]. [[category:UbuntuHelp]]
该页面使用的模板:
模板:From
(
查看源代码
)
模板:Languages
(
查看源代码
)(受保护)
模板:Languages/Lang
(
查看源代码
)(受保护)
返回至
UbuntuHelp:EmptyDiskSpace
。