linux实战(五)----压缩备份文件并删除原文件----实例解析
- UID
- 1066743
|
linux实战(五)----压缩备份文件并删除原文件----实例解析
原checkSpace.sh代码如下:
#!/bin/bash
function GetDiskSpc
{
if [ $# -ne 1 ]
then
return 1
fi
Folder="$1$"
DiskSpace=`df -k |grep $Folder |awk '{print $5}' |awk -F% '{print $1}'`
echo $DiskSpace
}
function CheckDiskSpc
{
DiskSpace=`GetDiskSpc $1`
echo "The system $Folder disk space is $DiskSpace%"
echo "The system $Folder disk space is $DiskSpace%" >> space.txt
if [ $DiskSpace -gt 90 ]
then
{
echo "The usage of system disk($Folder) is larger than 90%"
echo "The usage of system disk($Folder) is larger than 90%" >> space.txt
}
else
{
echo "The usage of system disk($Folder) is normal"
echo "The usage of system disk($Folder) is normal" >> space.txt
}
fi
}
CheckDiskSpc /boot
修改后的checkSpace.sh脚本如下:
#!/bin/bash
function GetDiskSpc
{
if [ $# -ne 1 ]
then
return 1
fi
Folder="$1$"
DiskSpace=`df -k |grep $Folder |awk '{print $5}' |awk -F% '{print $1}'`
echo $DiskSpace
}
function CheckDiskSpc
{
DiskSpace=`GetDiskSpc $1`
echo "The system $Folder disk space is $DiskSpace%"
echo "The system $Folder disk space is $DiskSpace%" >> space.txt
if [ $DiskSpace -gt 90 ]
then
{
echo "The usage of system disk($Folder) is larger than 90%"
echo "The usage of system disk($Folder) is larger than 90%" >> space.txt
}
else
{
echo "The usage of system disk($Folder) is normal"
echo "The usage of system disk($Folder) is normal" >> space.txt
}
fi
}
CheckDiskSpc /boot
tar cvf - /data/shell/space.txt > /data/shell/space.tar
rm space.txt
运行后结果如下:
发现已经成功把space.txt打包并删除了txt。
解压后可看到结果文件。
当然这里的路径可以进行相应调整。 |
|
|
|
|
|