linux中通过shell脚本复制文件,并用时间戳命名
2017-11-01 14:40
1306 查看
其中/var/log/ha/ha.log该文件是被复制文件,var/log/ha/log/$currentTimeStamp时间戳生成的文件复制的文件,/var/log/ha/cp_info.log是实行本shell的操作记录,同时本currentTimeStamp时间戳是长整型的
#!/bin/bash
#当前时间 <span style="font-family: Arial, Helvetica, sans-serif;">对应的毫秒时间戳</span>
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000))
#将current转换为时间戳,精确到毫秒
if [ ! -d "/var/log/ha/log/" ];then
mkdir -p /var/log/ha/log #-p为父类不存在则生成,存在不影响
fi
if test -s /var/log/ha/ha.log; then #是否为 空或存在
echo "is not empty $currentTimeStamp" >/var/log/ha/cp_info.log
cp /var/log/ha/ha.log "/var/log/ha/log/"$currentTimeStamp
echo -n "" > /var/log/ha/ha.log # -n为指定为全空,不留第一行
else
echo "empty or not exist $currentTimeStamp" >/var/log/ha/cp_info.log
fi
#!/bin/bash
#当前时间 <span style="font-family: Arial, Helvetica, sans-serif;">对应的毫秒时间戳</span>
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000))
#将current转换为时间戳,精确到毫秒
if [ ! -d "/var/log/ha/log/" ];then
mkdir -p /var/log/ha/log #-p为父类不存在则生成,存在不影响
fi
if test -s /var/log/ha/ha.log; then #是否为 空或存在
echo "is not empty $currentTimeStamp" >/var/log/ha/cp_info.log
cp /var/log/ha/ha.log "/var/log/ha/log/"$currentTimeStamp
echo -n "" > /var/log/ha/ha.log # -n为指定为全空,不留第一行
else
echo "empty or not exist $currentTimeStamp" >/var/log/ha/cp_info.log
fi
相关文章推荐
- linux通过awk命令,查询日志,分析数据,获取平均时间shell脚本
- linux下shell脚本移动、复制文件笔记
- Linux下自动清理超过指定大小的文件(shell脚本,通过du -sh或ls -l)
- linux文件远程传输客户端shell脚本与分布式客户机时间同步脚本
- linux中各个shell配置脚本文件的作用域和启动时间
- linux 批量复制某一类文件shell脚本
- linux通过/sys/class/gpio文件 操作gpio的shell脚本
- Git学习-->如何通过Shell脚本自动定时将Gitlab备份文件复制到远程服务器?
- shell脚本判断linux文件修改时间后执行操作
- 在Windows、Linux下,分别利用BAT批处理文件和Shell脚本,生成类似“20150605_111327.txt”命名的文件
- linux通过shell脚本修改文件内容
- Monkeyrunner 写脚本的技巧(shell 命令,文件操作)---关键点,python创建以时间命名的文件夹
- linux命令行中通过ssh复制文件(scp)到远程服务器
- Windows 和 Linux 下生成以当前时间命名的文件
- Linux系统shell脚本对字符串、数字、文件的判断
- linux 将文件内容赋值给shell脚本中的变量
- shell时间,shell创建文件,linux shell编写以日期时间为文件名的脚本学习笔记 (转)
- Linux通过shell脚本计算网卡流量
- Linux_shell脚本_遍历文件夹下所有文件
- Linux下复制、删除和重命名文件或文件夹