Shell脚本用于远程复制然后处理文件

时间:2013-02-22 14:27:49

标签: linux shell unix hp-ux

以下脚本运行正常。但是当我尝试向远程复制添加命令然后将变量FILENAME分配给从远程副本接收的文件时,while循环不起作用。我对脚本编写很陌生,所以我无法找到我所缺少的内容。请帮忙!

#!/bin/sh
#SCRIPT:  File processing
#PURPOSE: Process a file line by line with redirected while-read loop.
SSID=$1
ASID=$2
##rcp server0:/oracle/v11//dbs/${SSID}_ora_dir.lst /users/global/rahul/${ASID}_clone_dir.lst
##FILENAME=/users/global/rahul/${ASID}_clone_dir.lst
count=0
while read LINE
do
echo $LINE | sed -e "s/${SSID}/${ASID}/g"
count=`expr $count + 1`
done < $FILENAME
echo -e "\nTotal $count Lines read"
grep -v -e "pattern3" -e "pattern5" -e "pattern6" -e "pattern7" -e "pattern8" -e "pattern9" -e "pattern10" -e "pattern11" -e "
pattern12" ${ASID}_.lst > test_remote.test

1 个答案:

答案 0 :(得分:0)

当你说“while循环不起作用”时,如果你收到错误信息,你应该在你的问题中包含这个,以便给我们一个线索。

您确定rcp命令是否成功? /users/global/rahul/${ASID}_clone_dir.lst完成后文件rcp是否存在?

顺便说一句,while循环效率低下。这应该是等效的:

sed -e "s/${SSID}/${ASID}/g" < "$FILENAME"
count=$(wc -l "$FILENAME" | awk '{print $1}')
echo -e "\nTotal $count Lines read"