- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Feedback requested on output format for scripting
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
06-17-2005 04:37 AM
06-17-2005 04:37 AM
Feedback requested on output format for scripting
HP is designing a new function for an HP-UX command. This option would allow to pass a number of attribute names to the command, and the command output would display the associated values. This functionality would mostly be used in script mode, so we are looking for feedback on what is the best format to manage the output from a script.
Command:
cmd get -a
Output choices:
1) values only:
2) attr names + values:
3) attr names then values on a new line:
4) other proposal?
which is best and why?
Thanks!
Marie-Noelle
- Tags:
- syntax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2005 04:54 AM
06-17-2005 04:54 AM
Re: Feedback requested on output format for scripting
Also, what happens if a particular attribute doesn't exist or has no value? Hopefully there is some sort of place holder or string to indicate each case?
A variation on option2 may also work if each value is on a separate line.
As long as a non-existant attribute or null attribute value is indicated.
My 2nd option can be handy for scripting if doing:
while read LINE
do
DO YOUR STUFF
done < cmd get -a attr1 -a attr2 -a attr3
or something to that effect. That way you have each value on a separate line and can act accordingly if needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2005 04:59 AM
06-17-2005 04:59 AM
Re: Feedback requested on output format for scripting
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2005 05:07 AM
06-17-2005 05:07 AM
Re: Feedback requested on output format for scripting
It's also trivially easily to parse the line with Perl, awk, or the shell with
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2005 06:55 AM
06-17-2005 06:55 AM
Re: Feedback requested on output format for scripting
1. Since this function is going to be used in scriting i would go for listing the attributes in one single line so that they can be used easily for further processing.
2. I would prefer to have one more option for having attribute name displayed with value and the other one only the value which should be default.
e.g. i would add one more switch say v to the command to get attribute name along with the value and by default it should only display the value.
a) cmd get -a
b) cmd get -v -a
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2005 07:21 AM
06-17-2005 07:21 AM
Re: Feedback requested on output format for scripting
As Clay hints to, the prefered seperator might not be obvious. Why not have that be a command line option like AWKs -F. A good default would be TAB.
The parsing now is simple READ.
The basic Perl parsing now is a very simple:
@val=split /\t/, `$command`
or with no spaces in the values:
$_ = `$command`;
@val=split;
If this is an option which generates multiple, popular, attributes (like ps -ef) then a header line is needed. This could be implied by such multi-attribute selection.
You then just pre-parse the attributes and turn them into string/keyed indexes. In Perl:
$_=<>;
@attrs=split;
$i=0;
$attr{$a}=$i++ while($attrs[$i]};
$_=<>;
@val=split;
print $val[$attr{"attr2"}]."\n"
or
@attrs=split /\t/,<>;
for ($i=0;$i<@attrs;$i++) {$attr{$attrs[$i]}=$i};
@val=split /\t/,<>;
print $val[$attr{"attr2"}]."\n"
btw... I noticed one minor catch with a TAB versus the simple perl whitespace split. With an explicit split on TAB the potential newline after the last field become part of the field, so needs to be 'chomped' first:
$_=<>;
chomp;
@attrs=split /\t/;
I suppose a generic solution would be an attribute/value format string with recognized words for attribute and value:
-F "
-F "
-F "
nah!
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2005 07:55 AM
06-17-2005 07:55 AM
Re: Feedback requested on output format for scripting
In this case, it might be a good idea to add embedded quotes when a value contains whitespace. But that can also create a slippery slope...because what if a value contains an escaped quote...
Certainly it creates more food for thought.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2005 08:11 AM
06-17-2005 08:11 AM
Re: Feedback requested on output format for scripting
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2005 08:53 AM
06-17-2005 08:53 AM
Re: Feedback requested on output format for scripting
Thank you all for your interest in my question. Let me clarify one point, in our case, we always know the list of attribute names (they are passed as argument), and if an attribute does not exist, the whole command fails. Unless you feel this is not a good approach and you prefer to just say "not found" or some well known value if this happens.
Your replies so far are split between option 1 (single line) and option 2 (new line), and alsop between displaying the attribute name or not.
One solution would be to offer an option for each of those (display on single line versus display one per line; display attribute name or not).
All your comments are valid and appreciated. Feel free to add more,
Marie-Noelle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2005 09:10 AM
06-17-2005 09:10 AM
Re: Feedback requested on output format for scripting
with the default set to
because those poor lost souls whole prefer separate lines of output for each value now get it and us smart guys who want them all in one line get them like that. Moreover since the last value outputted gets a "\n" in both cases there is no additional coding required. There should be a man page and I always add a usage section requested with -u to all my scripts/programs.