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.
Would you like to provide a patch?
Yes, but it will take some time..
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.
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.
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.
Thanks a lot for the patch!
Volker, could you review the patch, please?
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 firstname.lastname@example.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 email@example.com.
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...
Ok, sorry then.
But a serious question, I'm genuinely interested: What does string_cache_strcpy() different from strcpy() from the Ansi C standard?
the prototype is different (void vs. char*), it is not inline and it is not redefined (and so it is usable)