归档脚本
[root@rac1 ~]# cat capstats
#!/bin/bash
MONTH=`date +%m`
DAY=`date +%d`
TIME=`date +%k%m%S`
SOURCE=/root/huang/huang/huang
BASE=/root/archive
mkdir -p $BASE/$MONTH/$DAY
DEST=$BASE/$MONTH/$DAY/arch$TIME
tar -cf $DEST $SOURCE
gzip $DEST
[root@rac1 ~]# ./capstats
tar: /root/archive/11/12/: Cannot open: Is a directory
tar: Error is not recoverable: exiting now
gzip: /root/archive/11/12/ is a directory -- ignored
gzip: 91111: No such file or directory
大家帮我分析分析,问题出在哪?
shell脚本
[解决办法]
把TIME赋值那里改成这样:
TIME=`date "+%H%m%S"`
你用%k的话,10点钟之前,小时数前面有个空格,导致下面的文件名DEST里面出现空格,tar命令会误解它
DEST=$BASE/$MONTH/$DAY/arch$TIME