Re: [Semibug] Need an example of libxo usage
On 15 Apr 2024, at 10:34, Mike Wayne wrote: > Any idea what package jq might be in? Never heard of it. https://www.freshports.org/textproc/jq/ Sean ___ Semibug mailing list Semibug@lists.nycbug.org https://lists.nycbug.org:8443/mailman/listinfo/semibug
Re: [Semibug] Need an example of libxo usage
On Sat, Apr 13, 2024 at 08:48:41AM -0700, ad...@bclug.ca wrote: > Mike Wayne wrote on 2024-04-12 15:55: > > I think JSON should do it via `jq`. Any idea what package jq might be in? Never heard of it. > printf "%s last login %s from %s\n" $(lastlogin --libxo json | jq -r > '.user,.login-time,.from') > A couple things to watch for: JSON / jq won't like a key with a hyphen, > such as login-time. I'd assume / hope that libxo would do the > transformation required for proper JSON. > > > Also, IFS might need tweaking as the date containing spaces will get > parsed into separate printf string placeholders. > > Or some `sed` transforms. Sounds like the --libxo option isn't all that functional as it appears to need additional commands to parse the output rather than just displaying arguments using command line options. ___ Semibug mailing list Semibug@lists.nycbug.org https://lists.nycbug.org:8443/mailman/listinfo/semibug
Re: [Semibug] Need an example of libxo usage
Mike Wayne wrote on 2024-04-12 15:55: Not too helpful. -f specifies the lastlogin FILE to use, not fields Ugh, confidently wrong. As mentioned, I'm trying to use --libxo text, not xml That's my dumb mistake. Looking to get lastlogin to print a single line: wayne last login: Fri Apr 12 15:06:16 2024 from 192.168.63.146 I'm guessing I need the printf equivalent for libxo but it appears not to be documented anywhere. I think JSON should do it via `jq`. printf "%s last login %s from %s\n" $(lastlogin --libxo json | jq -r '.user,.login-time,.from') I don't have any BSD system to try this on, but something like that ought to work. Example: └─» $ printf "%s %s %s\n" $(echo -n '{"user": "Wayne", "from": "192.168.63.146", "login_time": "today"}' | jq -r '.user, .login_time, .from') Wayne today 192.168.63.146 A couple things to watch for: JSON / jq won't like a key with a hyphen, such as login-time. I'd assume / hope that libxo would do the transformation required for proper JSON. Also, IFS might need tweaking as the date containing spaces will get parsed into separate printf string placeholders. Or some `sed` transforms. rb ___ Semibug mailing list Semibug@lists.nycbug.org https://lists.nycbug.org:8443/mailman/listinfo/semibug
Re: [Semibug] Need an example of libxo usage
On Fri, Apr 12, 2024 at 01:21:58PM -0700, Ron / BCLUG wrote: > Mike Wayne wrote on 2024-04-12 12:57: > > > What I can not figure out is how to select fields to print. > > To customize the output fields for the lastlogin command using libxo > with XML formatting in FreeBSD, you'll need to use the -f option to > specify the fields you want to include. Here's how you can do it: > > lastlogin -f field1,field2,... --libxo xml,pretty Not too helpful. -f specifies the lastlogin FILE to use, not fields As mentioned, I'm trying to use --libxo text, not xml Looking to get lastlogin to print a single line: wayne last login: Fri Apr 12 15:06:16 2024 from 192.168.63.146 I'm guessing I need the printf equivalent for libxo but it appears not to be documented anywhere. So something like: lastlogin --libxo '("%s last login in at %s from %s ", user, login-time, from)' wayne > Replace field1, field2, etc., with the specific fields you want to > include in the output. For example, if you want to include fields like > username, terminal, and login time, you would specify something like this: > > lastlogin -f username,terminal,login_time --libxo xml,pretty > > > This command will generate XML output with the specified fields in a > pretty format. Adjust the field names as per your requirements. ___ Semibug mailing list Semibug@lists.nycbug.org https://lists.nycbug.org:8443/mailman/listinfo/semibug
Re: [Semibug] Need an example of libxo usage
Ron / BCLUG wrote on 2024-04-12 13:28: Let us know if that works? By the way, the prompt I gave ChatGPT (which requires no login these days): using freebsd, how to choose output fields for command lastlogin --libxo xml,pretty ? ___ Semibug mailing list Semibug@lists.nycbug.org https://lists.nycbug.org:8443/mailman/listinfo/semibug
Re: [Semibug] Need an example of libxo usage
(Apologies if this is a duplicate - been mucking about with email server settings.) Mike Wayne wrote on 2024-04-12 12:57: What I can not figure out is how to select fields to print. To customize the output fields for the lastlogin command using libxo with XML formatting in FreeBSD, you'll need to use the -f option to specify the fields you want to include. Here's how you can do it: lastlogin -f field1,field2,... --libxo xml,pretty Replace field1, field2, etc., with the specific fields you want to include in the output. For example, if you want to include fields like username, terminal, and login time, you would specify something like this: lastlogin -f username,terminal,login_time --libxo xml,pretty This command will generate XML output with the specified fields in a pretty format. Adjust the field names as per your requirements. Let us know if that works? /ChatGPT ___ Semibug mailing list Semibug@lists.nycbug.org https://lists.nycbug.org:8443/mailman/listinfo/semibug
Re: [Semibug] Need an example of libxo usage
Mike Wayne wrote on 2024-04-12 12:57: What I can not figure out is how to select fields to print. To customize the output fields for the lastlogin command using libxo with XML formatting in FreeBSD, you'll need to use the -f option to specify the fields you want to include. Here's how you can do it: lastlogin -f field1,field2,... --libxo xml,pretty Replace field1, field2, etc., with the specific fields you want to include in the output. For example, if you want to include fields like username, terminal, and login time, you would specify something like this: lastlogin -f username,terminal,login_time --libxo xml,pretty This command will generate XML output with the specified fields in a pretty format. Adjust the field names as per your requirements. Let us know if that works? /ChatGPT ___ Semibug mailing list Semibug@lists.nycbug.org https://lists.nycbug.org:8443/mailman/listinfo/semibug
[Semibug] Need an example of libxo usage
Trying to correct some of the stupid that FreeBSD 13 did, I'm failing to get libxo to work. I ran lastlogin with the xml option to get the keys: % lastlogin --libxo xml,pretty wayne wayne pts/1 192.168.63.146 Fri Apr 12 15:06:16 2024 What I can not figure out is how to select fields to print. Based on what I can find, it looks like something like this should work: lastlogin --libxo '("%s last logged in from %s at %s", user, from, login-time)' wayne but it fails. I've tried tweaking quotes, backslashes, etc. with no luck. Google can not find single example of libxo usage anywhere that illustrates the corect way to specify key selection when using the --libxo option with a command. Can I get one? ___ Semibug mailing list Semibug@lists.nycbug.org https://lists.nycbug.org:8443/mailman/listinfo/semibug