Skip to content

Instantly share code, notes, and snippets.

/*
* parse output from 'resolvectl' or 'systemd-resolve --status'
* and outputs it in json format
*/
const { execSync } = require("child_process");
function resolvectl_parser_sync(){
const cspr = execSync("systemd-resolve --status | sed -e 's/: /=/' | sed -e 's#[\t ]##g' | awk -F= 'BEGIN{section=\"\"}{if($2!=\"\"){section=$1\" \"; print $1\" \"$2}else if($1!=\"\") {print section$1} else {section=\"\"; print section}}' ").toString();
var lines = cspr.split("\n");