KSH Output not coming correctly !!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH Output not coming correctly !!!
# 1  
Old 02-18-2011
KSH Output not coming correctly !!!

Guys,

I need some help, the output for my script below is causing me some issues....

Not sure where i am going wrong..

The out put should be all one line, but from some reasons its coming out on 4 lines...

Can you suggesst what i am doing wrong please!!!!!!


Code:
for MEDIA in `cat /tmp/freeze1 | awk '{print $2}'`
do
nbemmcmd -listmedia -mediaid $MEDIA | egrep "Media Type:|Last Mount:|Data Expiration:|Valid Images:" | awk '{print $3}' |
while read LINE
do
MEDIATYPE=`echo $LINE | cut -f1 -d" "`
LAST_MOUNT=`echo $LINE | cut -f2 -d" "`
DATE_EXPIRE=`echo $LINE | cut -f3 -d" "`
VALID_IMAGES=`echo $LINE | cut -f4 -d" "`
echo $MEDIA $MEDIATYPE $LAST_MOUNT $DATE_EXPIRE $VALID_IMAGES | awk '{printf " %-25s %-15s %-30s %-25s %-25s\n" , $1,$2,$3,$4,$5'} >> /tmp/FreezeMediaCheck.txt
done
done

Output of the script
==============

Code:
BAA139 DLT DLT DLT DLT
BAA139 02/01/2001 02/01/2001 02/01/2001 02/01/2001
BAA139 INFINITY INFINITY INFINITY INFINITY
BAA139 35 35 35 35
BAA151 DLT DLT DLT DLT
BAA151 - - - -
BAA151 INFINITY INFINITY INFINITY INFINITY
BAA151 29 29 29 29


Output should be
============
Code:
BAA139 DLT 02/01/2001 INFINITY 35

etc.....

Last edited by pludi; 02-18-2011 at 11:53 AM..
# 2  
Old 02-18-2011
Could you please post an example of output of the command
Code:
nbemmcmd -listmedia -mediaid $MEDIA | egrep "Media Type:|Last Mount:|Data Expiration:|Valid Images:" | awk '{print $3}'

(choosing a right $MEDIA value of course)

what gives the following ?

Code:
for MEDIA in `cat /tmp/freeze1 | awk '{print $2}'`
do
set -- `nbemmcmd -listmedia -mediaid $MEDIA | egrep "Media Type:|Last Mount:|Data Expiration:|Valid Images:" | awk '{print $3}' | xargs`
printf " %-25s %-15s %-30s %-25s %-25s\n" $MEDIA $1 $2 $3 $4 >>/tmp/FreezeMediaCheck.txt
done
done


Last edited by ctsgnb; 02-18-2011 at 01:10 PM..
# 3  
Old 02-18-2011
Output of the command

Code:
# nbemmcmd -listmedia -mediaid BAA139
NBEMMCMD, Version:6.5.3.1
====================================================================
Media GUID:                     debfb456-132e-140f-868f-fa2c33cad6d7
Media ID:                       BAA139
Partner:                        -
Media Type:                     DLT
Volume Group:                   ---
Application:                    Netbackup
Media Flags:                    1
Description:                    ------
Barcode:                        BAA139
Partner Barcode:                --------
Last Write Host:                ln2p1010inf
Created:                        09/19/2000 17:57
Time Assigned:                  03/31/2000 20:53
First Mount:                    02/01/2001 16:36
Last Mount:                     02/01/2001 16:36
Volume Expiration:              -
Data Expiration:                INFINITY
Last Written:                   04/01/2000 11:41
Last Read:                      02/01/2001 16:36
Robot Type:                     NONE
Robot Control Host:             -
Robot Number:                   -
Slot:                           -
Side/Face:                      -
Cleanings Remaining:            -
Number of Mounts:               1
Maximum Mounts Allowed:         0
Media Status:                   FULL MPX
Kilobytes:                      67161183
Images:                         35
Valid Images:                   35
Retention Period:               9
Number of Restores:             1
Optical Header Size Bytes:      1024
Optical Sector Size Bytes:      0
Optical Partition Size Bytes:   0
Last Header Offset:             0
Adamm Guid:                     00000000-0000-0000-0000-000000000000
Rsm Guid:                       00000000-0000-0000-0000-000000000000
Origin Host:                    nbkpmstr
Master Host:                    nbkpmstr
Server Group:                   NO_SHARING_GROUP
Upgrade Conflicts Flag:
Pool Number:                    10
Volume Pool:                    monthly_full2
Previous Pool Name:             -
Vault Flags:                    -
Vault Container:                -
Vault Name:                     -
Vault Slot:                     -
Session ID:                     -
Date Vaulted:                   -
Return Date:                    -
====================================================================
Command completed successfully.

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!


---------- Post updated at 04:07 PM ---------- Previous update was at 04:06 PM ----------

contents of "cat /tmp/freeze1 "


# BAA069 Assigned/Media - ExpireJustMediaLeaveUnassigned
# BAA139 Assigned/Media - ExpireJustMediaLeaveUnassigned
# BAA151 Assigned/Media - ExpireJustMediaLeaveUnassigned
# BAA156 Assigned/Media - ExpireJustMediaLeaveUnassigned
# BAA157 Assigned/Media - ExpireJustMediaLeaveUnassigned
# BAA160 Assigned/Media - ExpireJustMediaLeaveUnassigned
# BAA161 Assigned/Media - ExpireJustMediaLeaveUnassigned

Last edited by vgersh99; 02-18-2011 at 12:07 PM.. Reason: code tags, please!
# 4  
Old 02-18-2011
I updated my previous post, could you please make another try with the new suggestion and let me know?

---------- Post updated at 06:13 PM ---------- Previous update was at 06:11 PM ----------

oh, and make sure you cleaned up your
Code:
/tmp/FreezeMediaCheck.txt

before running the new code
# 5  
Old 02-18-2011
The command is working... Did not see your response... Not used this before...
Here is the output, after i edited the script

# cat /tmp/FreezeMediaCheck.txt
BAA139 DLT 02/01/2001 INFINITY 35
BAA151 DLT - INFINITY 29
BAA156 DLT - INFINITY 38


Thanks for your help!!!!!!!
# 6  
Old 02-19-2011
Code:
for MEDIA in `awk '{print $2}' /tmp/freeze1`
do
  nbemmcmd -listmedia -mediaid $MEDIA | awk '/Media Type:|Last Mount:|Data Expiration:|Valid Images:/ {printf $3 FS}END{printf RS}' 
done

# 7  
Old 02-19-2011
Code:
while read x MEDIA x
do
   nbemmcmd -listmedia -mediaid $MEDIA
done < /tmp/freeze1 | awk '/Media (Type|ID):|Last Mount:|Data Expiration:/{printf "%s ",$3}/Valid Images:/{print $3}' > /tmp/FreezeMediaCheck.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Top Command Output is not coming via Cronjob

Dear All, I created a small script to get the CPU, GIS usage etc automatically. However when i run this script manually its working , but when i run through cronjob i am not getting any output. Can anyone please help me on this. I am using SuseLinux. Thank you in advance. #!/bin/sh {... (2 Replies)
Discussion started by: Nitin Kapoor
2 Replies

2. Shell Programming and Scripting

Script Output coming in wrong format....

Hi team, getting output logs wrong in different format from telnet script ... getting Output.txt macro_outdoor_dist-6.0.0(v4_0_2) DN:1.3.903 (1101:100:11w:500:3:2:103:aa) macro_outdoor_dist-8.1.0(v3_1_0) DN:1.3.409 (N/A)... (3 Replies)
Discussion started by: Ganesh Mankar
3 Replies

3. Shell Programming and Scripting

Output not coming as desired.

Hi guys. I have a file containing some hosts and their IPs. host host1 192.168.2.10 host host2 192.168.2.11 host host3 192.168.2.12 I am writing a script where I want to print these values in 1 line. My script looks like RUNTIME_NODE=`cat hosts.properties | grep host` for i in... (7 Replies)
Discussion started by: Junaid Subhani
7 Replies

4. Shell Programming and Scripting

Output in for loop (ksh)

Hi , I'm writing the for loop script in home directory and wanted to get the files from /etc/data directory. #!/bin/ksh file_nm="/etc/dat" for test_data in $file_nm/fln* do echo "$test_data" done the code is executing successfully , but in the output it is showing ... (6 Replies)
Discussion started by: smile689
6 Replies

5. UNIX for Dummies Questions & Answers

ksh script - not getting output from ls

Hi! I'm a complete noob, and I'm trying to write a little script that takes a directory pathname as input from the CL, checks whether it exists, and if not creates it, then shows it worked using ls. Everything works beautifully except in the first instance, wherein the directory is created, ls... (10 Replies)
Discussion started by: sudon't
10 Replies

6. Solaris

sqlplus output from ksh.

Hi All, I have the below simple script. It runs just fine by itself when I manually invoke it. But once I put it in the crontab with entry: * * * * * /users/myuser/test.ksh >> /users/myuser/log/test.txt" It does NOT print the returned value ($REMAIN) from the DB!? The result in the... (3 Replies)
Discussion started by: steve701
3 Replies

7. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

8. Shell Programming and Scripting

Output coming in different line instead of single line

Hi Guys, I have an oracle database, I am trying to query the database and route it to file. But the records instead of coming in a single line, are coming in three lines. Can you please help me.. in this.. sqlplus -s $SRMUserid/$SRMPassword@$SRMServer<< EOF >log.out; select * from... (5 Replies)
Discussion started by: mac4rfree
5 Replies

9. Shell Programming and Scripting

script not displaying output correctly

Hi, I am having an issue with my script, ofcourse... I am trying to run commands against a remote server, I am pulling the hostnames or IPs from a file list, then looping thru and running the date cmd. I will be running different cmds just trying to get it working first. The ouput isn't... (2 Replies)
Discussion started by: dfezz1
2 Replies

10. Shell Programming and Scripting

Formatted output in KSH

Hi, Is there some way to get formatted output in ksh? Something like a properly alligned tabular format. I tried adding '\t' to echo statements, but it doesn't come properly alligned 'hello' A simple Hello 'helloworld' A helloworld statement I need the second coloumn to... (1 Reply)
Discussion started by: psynaps3
1 Replies
Login or Register to Ask a Question