Bug 6363 - smbstatus output is difficult to parse by scripts
smbstatus output is difficult to parse by scripts
Status: RESOLVED LATER
Product: Samba 3.4
Classification: Unclassified
Component: Client Tools
unspecified
x86 Linux
: P3 enhancement
: ---
Assigned To: Volker Lendecke
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-05-15 07:03 UTC by Hans-Peter Küchler
Modified: 2009-06-06 15:09 UTC (History)
1 user (show)

See Also:


Attachments
patch for samba-3.3.4/source/utils/status.c (19.67 KB, patch)
2009-05-27 06:50 UTC, Hans-Peter Küchler
no flags Details
patch for samba-3.3.4/docs-xml/manpages-3/smbstatus.1.xml (1.43 KB, patch)
2009-05-27 06:55 UTC, Hans-Peter Küchler
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hans-Peter Küchler 2009-05-15 07:03:07 UTC
I want to use the output from smbstatus by a script. The output is optical formatted but the fields are not really parseable by the script (no dedicated field separator...). It would be nice, if there will be an option to change the output to parseable. As an example, the fields could be sparated by tab character and every field can be surrounded with double quotes (every field or only if necessary). Every double quote and every backslash in the field content can be escaped by a backslash.
Comment 1 Karolin Seeger 2009-05-19 06:58:28 UTC
Would you like to provide a patch?
Comment 2 Hans-Peter Küchler 2009-05-19 13:46:50 UTC
Yes, but it will take some time..
Comment 3 Hans-Peter Küchler 2009-05-27 06:50:16 UTC
Created attachment 4211 [details]
patch for samba-3.3.4/source/utils/status.c

Tested with samba-3.3.4 and ubuntu 9.04 server. Contains the changes for the source file.
Comment 4 Hans-Peter Küchler 2009-05-27 06:55:57 UTC
Created attachment 4212 [details]
patch for samba-3.3.4/docs-xml/manpages-3/smbstatus.1.xml

Tested with samba-3.3.4 and ubunto 9.04 server, Contains the changes for the manpage. Hope, that all documentation will be generated from this file.
Comment 5 Hans-Peter Küchler 2009-05-27 07:09:06 UTC
There is a new option -m|--machine-readable, which switches the alternate output format on. See this snippet from the manpage:

Samba Version will not be given.
Empty blocks of information are not printed.
The ruler between heading of each block and data is not printed.
Each block will start with an empty line, followed by the block name, followed by the heading for this block.
The block name ends with a double colon.
Each column of information (and of heading) is separated from each other by tabulator (asc 9) character.
If (and only if) the information in one column contains a special character, than the information will be surrounded by double quotes and every special character will be preceded by one backslash character.
Special characters are: double quote, tabulator, newline, backslash.
If an information column is empty, than no quoting takes place. In this case two (or more, if more columns are empty) consecutive tabs will be printed.
The count of heading columns and information columns in each block is equal.

The behaviour of the program without the new option changes slightly:

All columns (incl. heading) have the minimal necessary width for the information. In process listing, the machine name/IP address gets an extra column with extra heading. Every block of informations has blockname before the heading.
Comment 6 Karolin Seeger 2009-05-29 03:26:00 UTC
Thanks a lot for the patch!

Volker, could you review the patch, please?
Comment 7 Volker Lendecke 2009-05-30 04:23:56 UTC
This is code that does not use Samba coding conventions at all. For example it directly uses malloc and free which in Samba goes through macros.

What does string_cache_strcpy() do differently from strcpy()? Why not use SMB_STRDUP instead of string_cache_strdup? What is a string_cache if not "just" an array of char *'s? We have for example a macro ADD_TO_ARRAY that also copes with talloc nicely.

Sorry, but in this form I will not put it upstream.

Your goal is definitely worthwile, but I think you should send a smaller patch to samba-technical@samba.org for wider discussion. I'm closing this as "later", please re-open when we've got a patch that is more in line with Samba conventions via samba-technical@samba.org.

Thanks,

Volker
Comment 8 Hans-Peter Küchler 2009-06-01 08:02:42 UTC
Thanks for reviewing this patch. I think, you are not interested in getting better software. You live in your own small C-samba world and have lost the contact to the current software developement evolution.
You should consider to change your language from C to some more sophisticated programming language. So you can avoid using macros and work arounds for programmers, which aren't able to design some C source carefully.
The patch works for me and I think, its better written than most of the other pieces of your client tools (in respect to C, with C++ it would be much easier to write such things). I'm not willing to change that patch, so you can close the bug.
Btw. the handling of help options is broken in your client tools, the help text (-?) and the manpage (-h) are different. But you can open your own bug...
Comment 9 Volker Lendecke 2009-06-01 08:16:28 UTC
Ok, sorry then.

But a serious question, I'm genuinely interested: What does string_cache_strcpy() different from strcpy() from the Ansi C standard?

Volker
Comment 10 Hans-Peter Küchler 2009-06-01 15:34:19 UTC
the prototype is different (void vs. char*), it is not inline and it is not redefined (and so it is usable)