Operating System - HP-UX
1833294 Members
3610 Online
110051 Solutions
New Discussion

Scripting issue : Can not read the second line

 
SOLVED
Go to solution
Dewa Negara_4
Regular Advisor

Scripting issue : Can not read the second line

Hi All,

I have a simple script using while read command below. When I tried to run it, it only run for first line (bdsn4013 SECU). It can not go to the second line,etc. Anyone can help to tell me what the issue is?

Please help. High score will be given.

Thanks and Best Regards,
Dewa

[root@bdhp4337:/var/opt/secu/parmlib]
# more transfer_sched.dat
bdsn4013 SECU
bdsn4002 SECU_QA
bdsn4014 SECU

-------------------------
TDIR=/var/tmp
PARMDIR=/var/opt/secu/parmlib
DEP=bdhm
DEPDIR=/usr/local/sysmgr/secu_refresh
LIST=$PARMDIR/transfer_sched.dat
LOGDIR=/var/opt/secu/log
LOG=$LOGDIR/transfer_secu.log
DATE=`date +%d%m%y`

grep -v "#" $LIST|grep -v "^$"|while read CLN PKG
do

#Test first parameter
if [ `remsh $CLN uname -s 2> /dev/null|grep -e SunOS -e AIX -e HP-UX |wc -l` -lt 1 ]
then echo "$DATE $CLN FAILED Either hostname is incorrect or remsh is not working from bdhp4337." |tee -a $LOG;continue;fi

#Test second parameter
case $PKG in
SECU|secu ) CONF=$PARMDIR/secu.conf ;;
SECU_QA|secu_qa ) CONF=$PARMDIR/secu_qa.conf ;;
SECU_TST|secu_tst) CONF=$PARMDIR/secu_tst.conf ;;
*) echo "$DATE $CLN FAILED Package should be either SECU, SECU_QA, or SECU_TST" |tee -a $LOG;continue ;;
esac

mkdir $TDIR/$$.${CLN}_log

N=1
cat $CONF|grep -v "#"|grep -v "^$" |while read REMDIR TODIR FILE OWNER PERM
do
mkdir $TDIR/$$.${CLN}_log/$N
if [ `echo $REMDIR|grep ^"./"|wc -l` -gt 0 ];then FROMDIR=`echo ${DEPDIR}${REMDIR#.}`
else FROMDIR=${REMDIR};fi

#Pull the files from Depot server BDHM
rcp -p $DEP:${FROMDIR}/$FILE $TDIR/$$.${CLN}_log/$N > /dev/null 2>&1
if [ `echo ${OWNER}#` != "#" ]; then chown ${OWNER} $TDIR/$$.${CLN}_log/$N/$FILE;fi > /dev/null 2>&1
if [ `echo ${PERM}#` != "#" ]; then chmod ${PERM} $TDIR/$$.${CLN}_log/$N/$FILE;fi > /dev/null 2>&1

#Transfer the files to the client
rcp -p $TDIR/$$.${CLN}_log/$N/$FILE $CLN:${TODIR} > /dev/null 2>&1

((N=$N + 1))
done

#Uncompress files, move to the correct place, etc...
F1=fn2acf.dat
F2=appids.dat
F3=grps.dat
F4=words
F5=pmd.tar

remsh $CLN "cd /var/tmp;uncompress $F1 $F2 $F3 $F4;chown root:sys $F1 $F2 $F3 $F4;chmod 644 $F1 $F2 $F3 $F4; \
mv $F1 $F2 $F3 $PARMDIR;mv $F4 /usr/dict;rm -f ${F1}.Z ${F2}.Z ${F3}.Z ${F4}.Z; \
/usr/bin/tar -xvf /var/opt/secu/$F5;rm -f /var/opt/secu/$F5" > /dev/null

echo "$DATE $CLN COMPLETED" |tee -a $LOG

rm -r $TDIR/$$.${CLN}_log
done
Santos
14 REPLIES 14
RAC_1
Honored Contributor
Solution

Re: Scripting issue : Can not read the second line

Is the every line in file seperated by new line??

od -c < your_file
There is no substitute to HARDWORK
Dewa Negara_4
Regular Advisor

Re: Scripting issue : Can not read the second line

Thanks.

I tried to use both "space" and "tab". Both gave me the same (while read can not go to the second line).

Thanks.
Dewa

[root@bdhp4337:/var/opt/secu/scripts]
# ./transfer_secu_DEV.sh
251005 bdsn4013 COMPLETED

[root@bdhp4337:/var/opt/secu/parmlib]
# more transfer_sched.dat
bdsn4013 SECU
bdsn4002 SECU_QA
bdsn4014 SECU

[root@bdhp4337:/var/opt/secu/parmlib]
# od -c < transfer_sched.dat
0000000 b d s n 4 0 1 3 \t S E C U \n b d
0000020 s n 4 0 0 2 \t S E C U _ Q A \n b
0000040 d s n 4 0 1 4 \t S E C U \n
0000055
Santos
RAC_1
Honored Contributor

Re: Scripting issue : Can not read the second line

What does following give??

How many lines do you get?? Post.
There is no substitute to HARDWORK
RAC_1
Honored Contributor

Re: Scripting issue : Can not read the second line

What does following give??
grep -v "#" $LIST|grep -v "^$"

Also as follows.
grep -v "#" $LIST|grep -v "^$"|od -c
There is no substitute to HARDWORK
Ralph Grothe
Honored Contributor

Re: Scripting issue : Can not read the second line

Hi Dewa,

I haven't read through your lengthy script to check for any possible errors there.
But despite I assume it's only the grepping part that reads the input lines.

How about trying something like

grep '^[^#]' $LIST | while read CLN PKG; do

at the beginning?
Madness, thy name is system administration
Dewa Negara_4
Regular Advisor

Re: Scripting issue : Can not read the second line

Hi Rac,

Sorry...what you mean?

When I tried to run the script, it only reads the first line. It never goes to the second line. Is there any problem with the config file /var/opt/secu/parmlib/transfer_sched.dat?

[root@bdhp4337:/var/opt/secu/parmlib]
# more transfer_sched.dat
bdsn4013 SECU
bdsn4002 SECU_QA
bdsn4014 SECU

[root@bdhp4337:/var/opt/secu/scripts]
# ./transfer_secu_DEV.sh
251005 bdsn4013 COMPLETED

Expected result as below:
# ./transfer_secu_DEV.sh
251005 bdsn4013 COMPLETED
251005 bdsn4002 COMPLETED
251005 bdsn4014 COMPLETED



Santos
Dewa Negara_4
Regular Advisor

Re: Scripting issue : Can not read the second line

Hi Rac,

Thanks. Here is the output:

[root@bdhp4337:/var/opt/secu/scripts]
# PARMDIR=/var/opt/secu/parmlib
You have mail in /var/mail/root

[root@bdhp4337:/var/opt/secu/scripts]
# LIST=$PARMDIR/transfer_sched.dat

[root@bdhp4337:/var/opt/secu/scripts]
# grep -v "#" $LIST|grep -v "^$"
bdsn4013 SECU
bdsn4002 SECU_QA
bdsn4014 SECU

[root@bdhp4337:/var/opt/secu/scripts]
# grep -v "#" $LIST|grep -v "^$"|od -c
0000000 b d s n 4 0 1 3 \t S E C U \n b d
0000020 s n 4 0 0 2 \t S E C U _ Q A \n b
0000040 d s n 4 0 1 4 \t S E C U \n
0000055
Santos
Dewa Negara_4
Regular Advisor

Re: Scripting issue : Can not read the second line

Hi Ralph,

Thanks. It gave me the same result.

grep '^[^#]' $LIST|while read CLN PKG
do

#Test first parameter
if [ `remsh $CLN uname -s 2> /dev/null|grep -e SunOS -e AIX -e HP-UX |wc -l` -lt 1 ]
then echo "$DATE $CLN FAILED Either hostname is incorrect or remsh is not working from bdhp4337." |tee -a $LOG;continue;fi

#Test second parameter
case $PKG in
SECU|secu ) CONF=$PARMDIR/secu.conf ;;
SECU_QA|secu_qa ) CONF=$PARMDIR/secu_qa.conf ;;
SECU_TST|secu_tst) CONF=$PARMDIR/secu_tst.conf ;;
"transfer_secu_DEV.sh" 68 lines, 2498 characters

[root@bdhp4337:/var/opt/secu/scripts]
# ./transfer_secu_DEV.sh
251005 bdsn4013 COMPLETED
Santos
RAC_1
Honored Contributor

Re: Scripting issue : Can not read the second line

I saw the remsh statement.
if [ `remsh $CLN uname -s 2> /dev/null|grep -e SunOS -e | -e HP-UX |wc -l` -lt 1 ]then echo "$DATE $CLN FAILED Either hostname is incorrect or remsh is not working from bdhp4337." |tee -a $LOG;continue;fi

Why not simplify it??

count=$(remsh $CLN 'uname -s 2>/dev/null'|egrep 'SunOS|AIX|HP-UX|wc -l)
if [[ ${count} -lt 1 ]];then
your_code here


There is no substitute to HARDWORK
Dewa Negara_4
Regular Advisor

Re: Scripting issue : Can not read the second line

Hi Rac,

Thanks. I have modified it. It still gave me the same problem.

Thanks.
Santos
RAC_1
Honored Contributor

Re: Scripting issue : Can not read the second line

set -vx and run the script. check the output carefully and you should be able to point out.
There is no substitute to HARDWORK
Sandman!
Honored Contributor

Re: Scripting issue : Can not read the second line

Dewa,

Run your script at the command line with debugging on.

# sh -x <script_name>

What's meant by "When I tried to run it, it only run for first line (bdsn4013 SECU). It can not go to the second line,etc." Please clarify?

regards!
Peter Nikitka
Honored Contributor

Re: Scripting issue : Can not read the second line

Hi,

I think the remsh-line is your problem:
if [ `remsh $CLN uname -s ...

remsh will read from stdin normally - change to 'remsh -n' so remsh will no try to read from stdin and so the second line will not be 'eaten'.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Al Langen_1
Advisor

Re: Scripting issue : Can not read the second line

So, what does this line do?

bdsn4013 SECU

Does it finish?

Turn on script and run it with set -x