将符号链接捕获到 Unix/Linux 变量中

将符号链接捕获到 Unix/Linux 变量中

假设我有一个包含一系列符号链接的文件夹:

ussdv103:en195d; default$  pwd
/oradba/app/oracle/admin/database1
ussdv103:en195d; default$  ls -ltr
exp -> /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/exp
dpdump -> /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/dpdump
backup -> /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/backup

然后我发出以下命令将其链接到不同的 STREAM 目录:

unlink $ORACLE_BASE/admin/database1/backup
unlink $ORACLE_BASE/admin/database1/dpdump
unlink $ORACLE_BASE/admin/database1/exp
mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/backup
mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/dpdump
mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/exp
ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/backup $ORACLE_BASE/admin/database1/backup
ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/dpdump $ORACLE_BASE/admin/database1/dpdump
ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/exp    $ORACLE_BASE/admin/database1/exp

然后我将使用以下命令将数据从旧的 STREAM 目录复制到新的 STREAM 目录:

cp -p -r /oradba/app/oracle/acfsmounts/global/STREAM##/database1/ /oradba/app/oracle/acfsmounts/global/STREAM1a/.

但我必须替换 ##,以便它反映旧 STREAM 目录的位置,因此命令将如下所示:

cp -p -r /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/ /oradba/app/oracle/acfsmounts/global/STREAM1a/.

如何捕获有关旧 STREAM 目录的信息取消链接,以便我的复制命令自动地取代##旧 STREAM 目录的正确位置?是否有一个 Unix/Linux 变量可以分配旧的符号链接,然后在复制命令中引用它?

答案1

使用命令 readlink 读取链接信息,将旧文件目标存储在变量中。

OLDBACKUP=`readlink $ORACLE_BASE/admin/database1/backup`
OLDDUMP=`readlink $ORACLE_BASE/admin/database1/backup`
OLDEXP=`readlink $ORACLE_BASE/admin/database1/exp`
NEWBACKUP="/oradba/app/oracle/acfsmounts/global/STREAM1a/database1/backup"
NEWDUMP="/oradba/app/oracle/acfsmounts/global/STREAM1a/database1/dpdump"
NEWEXP="/oradba/app/oracle/acfsmounts/global/STREAM1a/database1/exp"
unlink $ORACLE_BASE/admin/database1/backup
unlink $ORACLE_BASE/admin/database1/dpdump
unlink $ORACLE_BASE/admin/database1/exp
mkdir -p $NEWBACKUP
mkdir -p $NEWDUMP
mkdir -p $NEWEXP
ln -s $NEWBACKUP $ORACLE_BASE/admin/database1/backup
ln -s $NEWDUMP $ORACLE_BASE/admin/database1/dpdump
ln -s $NEWEXP    $ORACLE_BASE/admin/database1/exp

cp -p -r $OLDBACKUP $NEWBACKUP
cp -p -r $OLDDUMP $NEWDUMP
cp -p -r $OLDEXP $NEWEXP

相关内容