# cat /root/script/execute.sh
#!/bin/bash
#execute.sh
doc="/root/backup"
sudo sh /root/script/per_check.sh >> $doc/$( date '+%Y-%m-%d_%H-%M-%S')log.txt
if [ $? -eq 0 ]; then
find $doc/*.txt -mtime +1 -exec rm {} \;
else
echo fail
fi
-------------------------
# cat /root/script/per_check.sh
#!/bin/bash
#per_check.sh
i=1
printf "Memory-vol10\t\tDisk\t\tCPU\n"
end=$((SECONDS+3600))
while [ $SECONDS -lt $end ]; do
echo $i
free -m | awk 'NR==2{printf "RAM %.2f%%\t\t", $3*100/$2}'
df -h | awk '$NF==2"/"{printf "%s\t\t", $5}'
top -bn1 | grep load | awk '{printf "%.2f%%\t\t\n", $(NF-2)}'
#echo "$i$memory$disk$cpu"
let "i=i+1"
sleep 5
done
---------------------------
]# cat /root/backup/2020-08-15_04-00-01log.txt
Memory-vol10 Disk CPU
1
RAM 24.66% 0.04%
2
RAM 24.17% 0.03%
3
RAM 24.54% 0.03%
4
RAM 24.17% 0.03%
5
RAM 24.17% 0.02%
6
RAM 24.17% 0.02%
7
RAM 24.17% 0.26%
8
RAM 24.17% 0.24%
9
RAM 24.17% 0.22%
10
RAM 24.17% 0.20%
11
.
.
.
.
------------------------------------
[root@ansiblehost ~]# crontab -l
*/60 * * * * /root/script/execute.sh >/dev/null 2>&1
0 Comments