For loop not giving expected output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For loop not giving expected output
# 1  
Old 09-27-2016
For loop not giving expected output

Code:
#cat /tmp/input
old_array   old_dev  new_dev  new_array
0577    008AB   01744   0125
0577    008AC   01745   0125
0577    008AD   005C8   0125
0577    008AE   005C9   0125
0577    008AF   005CA   0125
0577    008B0   005CB   0125
0577    008B1   005CC   0125

Code:
cat test.sh
#!/bin/ksh
#set -x
for i in $(lspv |grep hdisk | awk '{print $1}')
do
        for j in $(cat /tmp/input | grep hdisk | awk '{print $3}')
        do
	        k=`lscfg -vl $i |grep $j`
        	print $i $k
        done
done

The script outputs all of the available disks multiple times but not the disk number and its corresponding new_dev value from /tmp/input file that I'm trying to get.
Note: One thing I just noticed is that the 'new_dev' value in 3rd column from /tmp/input file has 5 digits whereas the lscfg output in the script for 'k' variable has only 4 digit i.e., there is no leading '0', is it possible to add a leading zero to the value that goes into 'k'

Thanks!

Last edited by mbak; 09-27-2016 at 08:14 PM..
# 2  
Old 09-27-2016
Showing us an input file and non-working code without a clear explanation of what output you are trying to produce does't help a lot.

What does the lspv utility do? What output does it produce?

What does the lscfg utility do when invoked with the l and v flags and given one operand?

What output are you hoping to produce from the sample input you provided?
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 09-28-2016
My bad...I didn't realize about lspv and lscfg outputs.

Here is the sample output of lspv and lscfg for reference
Code:
# lspv | awk '{print $1}'
hdisk0
hdisk1
hdisk2
hdisk3
hdisk4
hdisk5
hdisk6
hdisk7


# lscfg -vl hdisk0 |grep LIC
        LIC Node VPD................1744

-->This value is same new_dev value from /tmp/input file

I'm trying to get hdisk number from lspv and its corresponding LIC value from lscfg based on /tmp/input file printed out.

Last edited by Don Cragun; 09-28-2016 at 02:54 AM.. Reason: Add CODE and ICODE tags.
# 4  
Old 09-28-2016
I can't see a relation between the outputs of the two commands given in post#3 connected by the /tmp/input contents.
Why don't you take a step back, and rephrase your request including ALL data available (and necessary to deal with it)?
This User Gave Thanks to RudiC For This Post:
# 5  
Old 09-28-2016
Thanks for your suggestion to take a step back,
here is the working code,

Code:
#!/bin/ksh
for i in $(lspv |grep hdisk | awk '{print $1}')
do
    LIC=$(lscfg -vl $i |grep LIC | cut -d\. -f17)
    DISK=$(cat /tmp/input | awk '{print $3}' | grep $LIC)
    [[ -n $DISK ]] && echo "$i:$LIC"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk not giving the output expected

Hello, I am practising awk and decided to compare two columns and print the result of the comparison as third column i/p data c1,c2,c3 1,a,b 1,b,b i am trying to compare the last two columns and if they match I am trying to print match else mismatch(Ideally i want that as a last column... (5 Replies)
Discussion started by: mkathi
5 Replies

2. Shell Programming and Scripting

CUT command not giving correct result inside loop

Hi, i have a source file and have 3 columns and separated by "|" .i want to split this 3 columns in different variable.When i am executing this values indivisually giving correct result but when the same execute inside a for loop,it's giving issues. Src file(jjj.txt) -------... (8 Replies)
Discussion started by: raju2016
8 Replies

3. AIX

Lsof command giving while loop

Hello, There is a process in AIX which is actually a oracle database user session but is running very slow When I use lsof it give below output lsof /proc/21955180 In while loop:256 In while loop:256 In while loop:256 In while loop:256 Value of I :183 np:1024 Please... (1 Reply)
Discussion started by: Vishal_dba
1 Replies

4. UNIX for Dummies Questions & Answers

Grep not giving expected results

Version: RHEL 5.8 I am doing a grep of the piped output from ps command as shown below. I am grepping for the pattern ora_dbw* . But, in the result set I am seeing strings with ora_dbr* as well like ora_dbrm_SDLM1DAS3 as shown below. Any idea why is this happening ? $ ps -ef | grep... (6 Replies)
Discussion started by: John K
6 Replies

5. AIX

lsrsrc not giving any output

Hi I am getting below output when I run lsrsrc IBM.ManagementServer sbkpshrasd02# lsrsrc "IBM.ManagementServer" Resource Persistent Attributes for IBM.ManagementServer I started the ctcas service but still no use. Stopped and started RMC. Any ideas what needs to be done. ----------... (1 Reply)
Discussion started by: wibhore
1 Replies

6. Programming

Test program not giving expected result

I have five classes. 2 composition classes,1 aggregation class and 1 dependency class.I have coded all the classes but one of my test program is not giving me the expected result.I have the following classes: TimeStamp Interval (composition of 2 TimeStamps) TimeSheet ( aggregation of many... (3 Replies)
Discussion started by: moraks007
3 Replies

7. Solaris

uptime and who giving improper or no output

Hello Everyone, One of our servers is showing a strange issue, let me paste the output root # uptime 4:37pm 3 users, load average: 0.00, 0.04, 0.04 Its been running since months but you can see after time there isn't any output like up 191 days(s). Even the who command with b... (1 Reply)
Discussion started by: vishalaswani
1 Replies

8. Shell Programming and Scripting

AWK not giving me correct output.

i have a line like this in my script IP=`get_IP <hostname> | awk '{ print $1 }' echo $IP the problem is get_IP <hostname> returns data formated as follows: ip 1.1.1.1 name server_name the code above returns 1.1.1.1 server_name and i just need the 1.1.1.1 I have tried to add "|... (5 Replies)
Discussion started by: mcdef
5 Replies

9. Shell Programming and Scripting

script not giving the desired output

Hi, I have a script in which an entry like this ..... FILENAME_B="PIC_${DATE}0732*.JPG" The script connects to an ATM and pull a pic file from it.The format for the file is like PIC_2008061400000001.JPG in the ATM. Means 1st 8 digit is the date(YYYYMMDD) field 2nd 8 digit means hrs... (2 Replies)
Discussion started by: Renjesh
2 Replies

10. Shell Programming and Scripting

The loop does not run as expected

Hi folks, I have the following configuration file: DB_LAYER=NO ADMIN_LAYER=NO RTESUB_LAYER=NO DB_HOST_NAME=tornado ADMIN_HOST_NAME=tornado RTESUB_HOST_NAME=tornado RESPONSE_FILE_SR=/tmp/SR.rsp INSTALL_SR_1=/home/Upgrade_4.7.1/Utilities/Install_SR:Y... (8 Replies)
Discussion started by: nir_s
8 Replies
Login or Register to Ask a Question