Board logo

标题: linux实战(六)----获取备份时间----实例解析(3) [打印本页]

作者: look_w    时间: 2019-5-11 14:03     标题: linux实战(六)----获取备份时间----实例解析(3)

脚本运用当前时间

修改后脚本为:

#!/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  

time=`date +%F`

tar cvf  - /data/shell/space.txt  > /data/shell/${time}space.tar

rm space.txt




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0