标签:pwd 一个 for echo 软连接 有一个 print data ls -l
场景为有一个路径的软连接要更新目标,但是软连接有两个问题一是数量比较大,二是路径格式是A目录下面的B目录下面的C目录下进行操作,因此写脚本进行批量操作:#!/bin/bash
source /etc/profile
#DATA_PATH="/data/share/6666/www"
DATA_PATH="/data/pool1/888888"
cd $DATA_PATH
DIR_NAME=" a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 "
for DIR1 in ${DIR_NAME};do
#echo ${DATA_PATH}/$DIR1
test -d ${DATA_PATH}/$DIR1
if [ $? -eq 0 ];then
cd ${DATA_PATH}/$DIR1
echo "第一级循环目录:",pwd
for DIR2 in ${DATA_PATH}/${DIR1}/${DIR_NAME};do
test -d ${DATA_PATH}/$DIR1/${DIR2}
if [ $? -eq 0 ];then
cd ${DATA_PATH}/$DIR1/${DIR2}
echo "第二级循环目录:",pwd
for NAME in /bin/ls -l ${DATA_PATH}/${DIR1}/${DIR2}
;do
if [ -L ${DATA_PATH}/${DIR1}/${DIR2}/${NAME} ];then
echo "第二级目录获取到的域名--->,$NAME"
for LINK_NAME in ${DATA_PATH}/${DIR1}/${DIR2}/${NAME};do
if [ -L ${LINK_NAME} ];then
cd ${DATA_PATH}/${DIR1}/${DIR2}
echo "域名源链接路径:,$LINK_NAME"
echo "当前绝对路径,pwd
"
S_NAME1=ls -l ${LINK_NAME} | awk ‘{print $9}‘
echo "源链接域名:,${S_NAME1}"
############################################################
D_NAME=ls -l ${LINK_NAME} | awk -F "/data/share/www/" ‘{print $2}‘
echo "目的链接路径:, ../../${D_NAME}"
############################################################
rm -rf ${S_NAME1}
ln -sv ../../${D_NAME} ${S_NAME1}
echo -e "当前域名处理完成,准备换行,\n"
fi
shift
done
shift
fi
shift
done
fi
shift
done
fi
shift
done
标签:pwd 一个 for echo 软连接 有一个 print data ls -l
原文地址:https://blog.51cto.com/14322562/2442693