请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为2013-09-23.log, 并且把磁盘的使用情况写到到这个文件中。
{{{密码回复可见}}}
{{{密码回复可见}}}
0
#!/bin/bash
MYTIME=`date +%F`
MYLOG=/root/$MYTIME.log
touch $MYLOG
df -h >> $MYLOG
然后加入任务计划,设置每天执行一次
MYTIME=`date +%F`
MYLOG=/root/$MYTIME.log
touch $MYLOG
df -h >> $MYLOG
然后加入任务计划,设置每天执行一次
0
#!/bin/bash
file="`date +%F`.log"
rm -rf $file
touch $file
echo "生成文件:$file"
df -h > $file
echo "磁盘信息写入"$file"成功!"
exit
file="`date +%F`.log"
rm -rf $file
touch $file
echo "生成文件:$file"
df -h > $file
echo "磁盘信息写入"$file"成功!"
exit
0
crontab 填写每天执行一次
* * */1 * * /home/1.sh >& /dev/null
脚本如下
#!/bin/sh
#author@zhanwang.xie
#date_20160106
date=`date "+%Y-%m-%d"`
/bin/df -h >$date.log
* * */1 * * /home/1.sh >& /dev/null
脚本如下
#!/bin/sh
#author@zhanwang.xie
#date_20160106
date=`date "+%Y-%m-%d"`
/bin/df -h >$date.log
0
#!/bin/bash
user=`whoami`
if_on=`chkconfig|grep crond |awk '{print $5}' |awk -F: '{print $2}'`
if [ $if_on = "off" ]
then
echo "please turn on crond service!"
exit 1
else
filename=`date +%F`.log
echo "0 0 * * * * touch $filename" >> /var/spool/cron/$user
echo "0 0 * * * * df -sh" >> /var/spool/cron/$user
fi
user=`whoami`
if_on=`chkconfig|grep crond |awk '{print $5}' |awk -F: '{print $2}'`
if [ $if_on = "off" ]
then
echo "please turn on crond service!"
exit 1
else
filename=`date +%F`.log
echo "0 0 * * * * touch $filename" >> /var/spool/cron/$user
echo "0 0 * * * * df -sh" >> /var/spool/cron/$user
fi
0
添加一个计划任务
crontab -e
1 1 * * * /tmp/script.sh
#!/bin/bash
fileName=`date +%F.log`
df -ah > /tmp/$fileName
crontab -e
1 1 * * * /tmp/script.sh
#!/bin/bash
fileName=`date +%F.log`
df -ah > /tmp/$fileName
0
#!/bin/bash
DAY=`date +%Y%m%d`
! ls /tmp/123/$DAY.log || touch $DAY.log
df -lh > /tmp/123/$DAY.log
DAY=`date +%Y%m%d`
! ls /tmp/123/$DAY.log || touch $DAY.log
df -lh > /tmp/123/$DAY.log
0
本帖最后由 蔡炳森 于 2016-2-27 22:49 编辑
#!/bin/bash
while :
do
m="`date +%Y-%m-%d`".log
touch $m
df -h > $m
sleep 60
done
#!/bin/bash
while :
do
m="`date +%Y-%m-%d`".log
touch $m
df -h > $m
sleep 60
done
0
本帖最后由 HMOM 于 2016-2-27 23:20 编辑
#!/bin/bash
d=`date "+%F"`
dir=/home/disk_usage
f=/home/disk_usage/$d.log
[ -d $dir ] || mkdir /home/disk_usage
if [ $? -eq 0 ];then
echo "-------------------------------------" >> $f
df -Th >> $f
fi
#!/bin/bash
d=`date "+%F"`
dir=/home/disk_usage
f=/home/disk_usage/$d.log
[ -d $dir ] || mkdir /home/disk_usage
if [ $? -eq 0 ];then
echo "-------------------------------------" >> $f
df -Th >> $f
fi
0
#!/bin/bash
DATE=`date +%F`
DIR=/logs
if [ -d $DIR ] ; then
df -h > $DIR/$DATE.log
else
echo "$DIR not exsit"
fi
DATE=`date +%F`
DIR=/logs
if [ -d $DIR ] ; then
df -h > $DIR/$DATE.log
else
echo "$DIR not exsit"
fi
0
本帖最后由 西瓜.M 于 2016-4-27 10:22 编辑
#vim /usr/local/sbin/file.sh
echo `df -h` > /tmp/test/$(date +%F)
#vim /var/spool/cron/root
0 10 * * * sh /usr/local/sbin/file.sh
#vim /usr/local/sbin/file.sh
echo `df -h` > /tmp/test/$(date +%F)
#vim /var/spool/cron/root
0 10 * * * sh /usr/local/sbin/file.sh
0
[root@67 shell]# vim disk_use.sh
#!/bin/bash
n=`date +'%Y-%m-%d'`
l=$n.log
echo "Today is $n.The use of disks :" > /tmp/$l
df -h >> /tmp/$l
[root@67 shell]# crontab -e
0 2 * * * ls
0 0 * * * sh /usr/local/sbin/nginx_logrotate >>/tmp/nginx_logrotate_log
35 23 * * * /bin/bash /root/shell/disk_use.sh
#!/bin/bash
n=`date +'%Y-%m-%d'`
l=$n.log
echo "Today is $n.The use of disks :" > /tmp/$l
df -h >> /tmp/$l
[root@67 shell]# crontab -e
0 2 * * * ls
0 0 * * * sh /usr/local/sbin/nginx_logrotate >>/tmp/nginx_logrotate_log
35 23 * * * /bin/bash /root/shell/disk_use.sh
0
- #!/bin/bash
- d=`date +%H:%M`
- m=`date +%F`
- if [ $d != "12:03" ];then
- touch $m.log
- free -m > $m.log
- fi
0
脚本内容是
#!/bin/bash
##
hdd=`df -h |awk -F '[ ]+' '{print $1}''{print $5}'|grep -v Filesystem |grep -v Use`
sj=`date +%F`
echo $hdd > /tmp/$sj.log
然后把这个脚本放到计划任务里 每天执行
#!/bin/bash
##
hdd=`df -h |awk -F '[ ]+' '{print $1}''{print $5}'|grep -v Filesystem |grep -v Use`
sj=`date +%F`
echo $hdd > /tmp/$sj.log
然后把这个脚本放到计划任务里 每天执行
0
本帖最后由 smatch 于 2016-5-29 16:05 编辑
crontab
log.sh
crontab
- 0 0 * * * /bin/bash log.sh
log.sh
- #!/bin/bash
- a=`date +%Y-%m-%d`
- touch $a.log
0
- #!/bin/bash
- ###请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为2013-09-23.log, 并且把磁盘的使用情况写到到这个文件中。
- a=`pwd`
- d=`date +%Y-%m-%d`
- #while :;
- #do
- if [ -n $a ]
- then
- c=`df -h | awk 'NR==3{print $4}'`
- c1=`df -h | awk 'NR==4{print $4}'`
- swap=`df -h | awk 'NR==5{print $4}'`
- echo "根目录使用率为"$c > $d.log
- echo "tmpfs 使用率为"$c1 >> $d.log
- echo "boot目录使用率为"$swap >> $d.log
- fi
编辑回复