`

初始化目录脚本

 
阅读更多

        一个线上脚本一般需要使用将数据放到对应的目录。一旦目录被错误删除,整个脚本流程可能被打破,导致无法继续执行。以下分享了对应的代码。

 

#!/bin/sh
#获取基础目录
SOURCE="$0"
while [ -h "$SOURCE"  ];
do # resolve $SOURCE until the file is no longer a symlink
    DIR="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    [[ $SOURCE != /*  ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"

#创建data目录
dataDir=${DIR}/data
if [ ! -d ${dataDir} ]
then
    echo "not exists ${dataDir}"
    mkdir ${dataDir}
else echo "${dataDir} existed"
fi
#创建tmp目录
tmpDir=${DIR}/tmp
if [ ! -d ${tmpDir} ]
then
    echo "not exists ${tmpDir}"
    mkdir ${tmpDir}
else echo "${tmpDir} existed"
fi

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics