每月 1 日轮换脚本中的文件名

每月 1 日轮换脚本中的文件名

我有一个脚本,在 crontab 中每 5 分钟运行一次,并将输出写入同一个文件。我想移动此文件并附加该月的 1 号日期。

到目前为止,我已经有了这样的逻辑:

date=`date +"%d/%m/%Y-%H:%M"`
date1=`date +"%d%m%Y%H%M"`
condition=`date +"01/%m/%Y-00:00"`

if [[ $date == $condition ]];then
  mv variable_check.txt variable_check-${date1}.txt
  mv ADT_`hostname`_active_users.txt ADT_`hostname`_active_users-${date1}.txt
else
  :
fi

我并不是说上述方法不起作用,而是可能有更优选的方法来实现我需要完成的任务。

相关内容