- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting issue : Can not read the second line
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 08:28 PM
10-24-2005 08:28 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 08:35 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 08:46 PM
10-24-2005 08:46 PM
Re: Scripting issue : Can not read the second line
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 08:54 PM
10-24-2005 08:54 PM
Re: Scripting issue : Can not read the second line
How many lines do you get?? Post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 08:59 PM
10-24-2005 08:59 PM
Re: Scripting issue : Can not read the second line
grep -v "#" $LIST|grep -v "^$"
Also as follows.
grep -v "#" $LIST|grep -v "^$"|od -c
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 09:02 PM
10-24-2005 09:02 PM
Re: Scripting issue : Can not read the second line
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 09:03 PM
10-24-2005 09:03 PM
Re: Scripting issue : Can not read the second line
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 09:06 PM
10-24-2005 09:06 PM
Re: Scripting issue : Can not read the second line
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 09:13 PM
10-24-2005 09:13 PM
Re: Scripting issue : Can not read the second line
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 09:20 PM
10-24-2005 09:20 PM
Re: Scripting issue : Can not read the second line
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 09:35 PM
10-24-2005 09:35 PM
Re: Scripting issue : Can not read the second line
Thanks. I have modified it. It still gave me the same problem.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 09:47 PM
10-24-2005 09:47 PM
Re: Scripting issue : Can not read the second line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2005 01:25 AM
10-25-2005 01:25 AM
Re: Scripting issue : Can not read the second line
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2005 07:03 PM
10-25-2005 07:03 PM
Re: Scripting issue : Can not read the second line
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2005 02:09 AM
10-26-2005 02:09 AM
Re: Scripting issue : Can not read the second line
bdsn4013 SECU
Does it finish?
Turn on script and run it with set -x