我正在尝试使用Nested用于对目录Structure中的子目录进行更新,j的值是基于前一个for中的i的值来获取的,脚本似乎并未获取j正确,这是附加的脚本,挑战似乎在于在cat /tmp/
echo $ i``中执行j的行,我试图简单地放入$ i,但似乎没有选择它,对对此问题表示赞赏,预先感谢。
#!/bin/bash
set -xv
rm /tmp/MDMs /tmp/MDMswithBlanks
rm -rf /tmp/Tenants*
cd /images/SCWA-SaaS/latest/config/
ls -lrt | awk '{print $9;}' | grep -v "controller" >> /tmp/MDMswithBlanks
sed '/^$/d' /tmp/MDMswithBlanks >> /tmp/MDMs
for i in `cat /tmp/MDMs`
do
cd /images/SCWA-SaaS/latest/config/
cd $i
ls -lrt | grep "drwx" | awk '{print $9;}' >> /tmp/`echo $i`
**for j in `cat /tmp/`echo $i``**
do
cd /images/SCWA-SaaS/latest/config/
cd $i
cd $j
cd /tmp
mkdir $i$j
cd /images/SCWA-SaaS/latest/config/
cd $i
cd $j
cp -p configFiles.zip /tmp/`echo $i$j`
cd /tmp/`echo $i$j`
unzip configFiles.zip
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/Tivoli/TWS/GSKit32/8/lib
/usr/Tivoli/TWS/GSKit32/8/bin/gsk8capicmd -cert -add -file /tmp/DigiCertTrustedRoot.pem -label DigiCertTrustedRoot -db /tmp/`echo $i$j`/TWSClientKeyStore.kdb -pw default
/usr/Tivoli/TWS/GSKit32/8/bin/gsk8capicmd -cert -add -file /tmp/DigiCertCA2.pem -label DigiCertCA2 -db /tmp/`echo $i$j`/TWSClientKeyStore.kdb -pw default
rm configFiles.zip
zip configFiles.zip TWSClientKeyStore.kdb installAgent.properties
chown root:root configFiles.zip
chmod 544 configFiles.zip
cd /images/SCWA-SaaS/latest/config/
cd $i
cd $j
#rm configFiles.zip
cp -p /tmp/`echo $i$j`/configFiles.zip .
#rm -rf /tmp/`echo $i$j`
done
done
关于, Sriram.V
答案 0 :(得分:1)
要遍历目录/子目录,最好使用find
命令:
for i in $(find /tmp/MDMs -type d)
do
...
done
答案 1 :(得分:0)
感谢大家的建议,我设法成功地执行了此操作,因此对整个路径使用变量TENANT =“ / tmp / CERT / echo $i
”:
#!/bin/bash
set -xv
rm /tmp/CERT/MDMs /tmp/CERT/MDMswithBlanks
cd /images/SCWA-SaaS/latest/config/
ls -lrt | awk '{print $9;}' | grep -v "controller" >> /tmp/CERT/MDMswithBlanks
sed '/^$/d' /tmp/CERT/MDMswithBlanks >> /tmp/CERT/MDMs
for i in `cat /tmp/CERT/MDMs`
do
cd /images/SCWA-SaaS/latest/config/
cd $i
ls -lrt | grep "drwx" | awk '{print $9;}' >> /tmp/CERT/`echo $i`
TENANT="/tmp/CERT/`echo $i`"
for j in `cat $TENANT`
do
cd /images/SCWA-SaaS/latest/config/
cd $i
cd $j
cd /tmp/CERT
mkdir $i$j
cd /images/SCWA-SaaS/latest/config/
cd $i
cd $j
TENANT_PREFIX="/tmp/CERT/`echo $i$j`"
cp -p configFiles.zip $TENANT_PREFIX
cd $TENANT_PREFIX
unzip configFiles.zip
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/Tivoli/TWS/GSKit32/8/lib
/usr/Tivoli/TWS/GSKit32/8/bin/gsk8capicmd -cert -add -file /tmp/DigiCertTrustedRoot.pem -label DigiCertTrustedRoot -db $TENANT_PREFIX/TWSClientKeyStore.kdb -pw default
/usr/Tivoli/TWS/GSKit32/8/bin/gsk8capicmd -cert -add -file /tmp/DigiCertCA2.pem -label DigiCertCA2 -db $TENANT_PREFIX/TWSClientKeyStore.kdb -pw default
rm configFiles.zip
zip configFiles.zip TWSClientKeyStore.kdb installAgent.properties
chown root:root configFiles.zip
chmod 544 configFiles.zip
cd /images/SCWA-SaaS/latest/config/
cd $i
cd $j
rm configFiles.zip
cp -p $TENANT_PREFIX/configFiles.zip .
#rm -rf $TENANT_PREFIX
done
done