请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为2013-09-23.log, 并且把磁盘的使用情况写到到这个文件中。
{{{密码回复可见}}}
{{{密码回复可见}}}
0
本帖最后由 菠萝 于 2013-9-24 09:05 编辑
#!/bin/bash
today=`date +%Y-%m-%d`
today1=`date +%H:%M:%S`
echo "$today1" >> $today.log
df >> $today.log
echo "--------------------------------------------------------------------" >> $today.log
#!/bin/bash
today=`date +%Y-%m-%d`
today1=`date +%H:%M:%S`
echo "$today1" >> $today.log
df >> $today.log
echo "--------------------------------------------------------------------" >> $today.log
0
本帖最后由 Hello_Lemon 于 2013-9-23 10:25 编辑
#! /bin/bash
#请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为2013-09-23.log, 并且把磁盘的使用情况写到到这个文件中。
s=`date +"%Y-%m-%d"`
touch $s.log
df>$s.log
#! /bin/bash
#请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为2013-09-23.log, 并且把磁盘的使用情况写到到这个文件中。
s=`date +"%Y-%m-%d"`
touch $s.log
df>$s.log
1
赞同来自: xiaojiajia
#!/bin/bash
for i in "`date +%Y-%m-%s`.log"
do
touch $i
echo `/bin/df -h`>$i
done
对于crontab话,我方法是:编辑crontab,添加一行 * * */1 * * /usr/local/sbin/1.sh
for i in "`date +%Y-%m-%s`.log"
do
touch $i
echo `/bin/df -h`>$i
done
对于crontab话,我方法是:编辑crontab,添加一行 * * */1 * * /usr/local/sbin/1.sh
0
- #!/bin/bash
- while true
- do
- log=`date +"%Y-%m-%d"`;
- log=${log}.log;
- df -ah > $log ;
- sleep 24h;
- done;
-
0
本帖最后由 地平线 于 2013-9-23 14:15 编辑
# crontab -l
00 * * * * /bin/sh /dir/4.sh 2>1&
#cat /dir/4.sh
#!/bin/bash
name=`echo /dir/$(date +%F).log`
df -h > $name
# crontab -l
00 * * * * /bin/sh /dir/4.sh 2>1&
#cat /dir/4.sh
#!/bin/bash
name=`echo /dir/$(date +%F).log`
df -h > $name
0
本帖最后由 chekir 于 2013-9-24 10:15 编辑
另外,使用crontab每天定时创建以日期为开头的.log的文件
- #! /bin/basn
- d=`date "+%y-%M-%d"`
- df |tee $d.log [color=Lime]#df >>$d.log[/color]
- crontab -e
- 0 7 * * * /bin/sh /usr/local/sbin/d.sh
0
#! /bin/bash
while :;do
i=`date +%Y-%m-%d`
touch /home/zuoye/$i.log
df -h > /home/zuoye/$i.log
sleep 1d
done
while :;do
i=`date +%Y-%m-%d`
touch /home/zuoye/$i.log
df -h > /home/zuoye/$i.log
sleep 1d
done
0
vi /root/1.sh
#按日期生成日志文件并将磁盘空间写入日志文件
#!/bin/bash
date=`date +%F`
touch $date.log
df -HT >> $date.log
crontab -e
0 0 * * * /bin/bash /root/1.sh
#按日期生成日志文件并将磁盘空间写入日志文件
#!/bin/bash
date=`date +%F`
touch $date.log
df -HT >> $date.log
crontab -e
0 0 * * * /bin/bash /root/1.sh
0
编写脚本:/tmp/shell/disk.sh
#!/bin/bash
## This script is for echo disk's usage condition.
## Writed by Louis on 2014/08/27 17:54
if [ -e /var/log/disk/`date +%F`.log ];then
echo "`date +'%F %T'` ERR:log file is exist." >> /var/log/disk/error.log
echo "`date +'%F %T'; df -h`" >> /var/log/disk/`date +%F`.log.backup
else
echo "`date +'%F %T'; df -h`" >> /var/log/disk/`date +%F`.log
fi
加入计划任务:crontab -e -u root
10 0 * * * /bin/bash /tmp/shell/disk.sh
#!/bin/bash
## This script is for echo disk's usage condition.
## Writed by Louis on 2014/08/27 17:54
if [ -e /var/log/disk/`date +%F`.log ];then
echo "`date +'%F %T'` ERR:log file is exist." >> /var/log/disk/error.log
echo "`date +'%F %T'; df -h`" >> /var/log/disk/`date +%F`.log.backup
else
echo "`date +'%F %T'; df -h`" >> /var/log/disk/`date +%F`.log
fi
加入计划任务:crontab -e -u root
10 0 * * * /bin/bash /tmp/shell/disk.sh
0
#!/bin/bash
CURR_TIME=`date +%F`
LOG_FILE=$CURR_TIME.log
df -h > $LOG_FILE
echo " 0 0 * * * /usr/local/bin/log.sh > /dev/null 2>&1" >> /var/spool/cron/root {:5_121:}
CURR_TIME=`date +%F`
LOG_FILE=$CURR_TIME.log
df -h > $LOG_FILE
echo " 0 0 * * * /usr/local/bin/log.sh > /dev/null 2>&1" >> /var/spool/cron/root {:5_121:}
0
#!/bin/bash
T=`date +"%Y-%m-%d"`
df -h >/chengcheng/$T.log
或者:
#!/bin/bash
df -h >/chengcheng/$(date +"%Y-%m-%d").log
ls -l $(date +"%Y-%m-%d").log
T=`date +"%Y-%m-%d"`
df -h >/chengcheng/$T.log
或者:
#!/bin/bash
df -h >/chengcheng/$(date +"%Y-%m-%d").log
ls -l $(date +"%Y-%m-%d").log
0
本帖最后由 pykihwfn 于 2014-11-1 11:50 编辑
00 00 * * * df -h >> /test/`date +%Y-%m-%d`.log #每天的00:00 把磁盘的使用情况写入以"当天的日期.log"文件里。
PS:晕。。。。写成了计划任务了。。。。。
00 00 * * * df -h >> /test/`date +%Y-%m-%d`.log #每天的00:00 把磁盘的使用情况写入以"当天的日期.log"文件里。
PS:晕。。。。写成了计划任务了。。。。。
0
创建脚本在root目录下(随便哪个目录)
内容:
#!/bin/bash
df -h > `date +%Y-%m-%d`
保存为date.sh,用chmod +x date.sh 增加执行权限。
Terminal里面输入:crontab -e
输入以下内容:
00 00 * * * df -h > `date +%Y-%m-%d`
以后每天零点零分都会在目录下生成一个以日期命名的文件,并在里面写入磁盘使用情况的信息。
内容:
#!/bin/bash
df -h > `date +%Y-%m-%d`
保存为date.sh,用chmod +x date.sh 增加执行权限。
Terminal里面输入:crontab -e
输入以下内容:
00 00 * * * df -h > `date +%Y-%m-%d`
以后每天零点零分都会在目录下生成一个以日期命名的文件,并在里面写入磁盘使用情况的信息。
0
crontab -e
59 23 * * * sh /myscripts/diskinfo.sh
- #!/bin/bash
- # This is a disk info script.
- # Writen by Wangxiaoqiang 2014-11-21.
- echo "################### Disk info ####################" > $(date +%F).log
- df -HT >> /data/$(date +%F).log
- #End
crontab -e
59 23 * * * sh /myscripts/diskinfo.sh
0
将此脚本加入到crontab即可,也可写脚本加到crontab
- #!/bin/bash
- FILENAME=`date +%F`
- FILENAME=$FILENAME.log
- echo $FILENAME
- touch $FILENAME
- if [ -e $FILENAME ]
- /bin/df -h 1>$FILENAME
- fi
将此脚本加入到crontab即可,也可写脚本加到crontab
0
#!/bin/bash
#This is written by renhongyang in 2014-12-9
a=$( date +%Y-%m-%d )
logfile=$a.log
df -h>$logfile
#This is written by renhongyang in 2014-12-9
a=$( date +%Y-%m-%d )
logfile=$a.log
df -h>$logfile
0
本帖最后由 川娃子在大连 于 2014-12-16 15:12 编辑
#!/bin/bash
# -------------------------------------------------------------------------------
# Filename: amingtest.sh
# Revision: 1.0
# Date: 2014/12/16
# Author: FUQIANG LI
# Email: 317377106@qq.com
# Description: creat log file named as date.log,like 2014-12-16.log,to save the
# message of disk using.
# Notes: aminglinux shell exercises of 2013-09-23
# -------------------------------------------------------------------------------
if [ -d ~/log ];then
cd ~/log
else
mkdir ~/log
cd ~/log
fi
creatdate=`date +%F`
df -hT > ${creatdate}.log
#!/bin/bash
# -------------------------------------------------------------------------------
# Filename: amingtest.sh
# Revision: 1.0
# Date: 2014/12/16
# Author: FUQIANG LI
# Email: 317377106@qq.com
# Description: creat log file named as date.log,like 2014-12-16.log,to save the
# message of disk using.
# Notes: aminglinux shell exercises of 2013-09-23
# -------------------------------------------------------------------------------
if [ -d ~/log ];then
cd ~/log
else
mkdir ~/log
cd ~/log
fi
creatdate=`date +%F`
df -hT > ${creatdate}.log
0
- #!/bin/bash
- #written by yangkun at 2014-12-16
- #
- while sleep 86400;do
- m=`date +%F`
- n=$m.log
- touch $n
- df -h > $n
- echo "log has been backed up"
- done
0
[root@localhost sbin]# cat 01.sh
#!/bin/bash
d=`date +%F`
df -h >/tmp/test/"$d".log
[root@localhost sbin]# crontab -l
00 01 * * * root /bin/bash /usr/local/sbin/01.sh
请铭哥查看 ,如有不对请指出
#!/bin/bash
d=`date +%F`
df -h >/tmp/test/"$d".log
[root@localhost sbin]# crontab -l
00 01 * * * root /bin/bash /usr/local/sbin/01.sh
请铭哥查看 ,如有不对请指出
0
自己加了一个小需求,在/usr/local/sbin/下面是否有log文件夹,如果有则生成文件;没有先创建该文件夹,再生成文件。
#! /bin/bash
# create filenname
filename=`date +%F`
logfile=$filename.log
# save filepath,write diskinfo
if [ -e /usr/local/sbin/log/ ]; then
df -h > /usr/local/sbin/log/$logfile;
else
mkdir /usr/local/sbin/log/;
df -h > /usr/local/sbin/log/$logfile;
fi
添加任务计划
crontab -e #编写任务
18 22 * * * /bin/sh /usr/local/sbin/1.sh # 每天的22点18分去执行1.sh脚本
#! /bin/bash
# create filenname
filename=`date +%F`
logfile=$filename.log
# save filepath,write diskinfo
if [ -e /usr/local/sbin/log/ ]; then
df -h > /usr/local/sbin/log/$logfile;
else
mkdir /usr/local/sbin/log/;
df -h > /usr/local/sbin/log/$logfile;
fi
添加任务计划
crontab -e #编写任务
18 22 * * * /bin/sh /usr/local/sbin/1.sh # 每天的22点18分去执行1.sh脚本
编辑回复