Tag Archives: unix

dmidecode to json using awk

dmidecode | awk '
BEGIN {
	printf "{"
	first_entry = 0
	is_array = 0
	array_first_entry = 0
}
{
	if ($0 ~ /^Handle/) {
		if (is_array) {
			printf "]"
			is_array = 0
		}
		if (first_entry) {
			printf "},"
		}
		first_entry = 1

		gsub(/,$/, "", $2);
		printf "\"%s\": {", $2

		getline line
		printf "\"_description\": \"%s\"", line

		gsub(/,$/, "", $5);
		printf ",\"_type\": \"%s\"", $5

		gsub(/,$/, "", $6);
		printf ",\"_bytes\": \"%s\"", $6
	} else if ($0 ~ /:/) {
		if (is_array) {
			printf "]"
			is_array = 0
		}
		gsub(/^[[:space:]]+/, "", $0)
		split($0, a, ": ");
		if (length(a) > 1) {
			gsub(/"/, "\\\"", a[2])
			gsub(/[[:space:]]+$/, "", a[2])
			printf ",\"%s\": \"%s\"", a[1], a[2]
		}
		else if (length(a) == 1) {
			gsub(/:$/, "", a[1])
			printf ",\"%s\": [", a[1]
			is_array = 1
			array_first_entry = 0
		}
	}
	else if (is_array && NF > 0) {
		if (array_first_entry) {
			printf ","
		}
		array_first_entry = 1
		gsub(/^[[:space:]]+/, "", $0)
		gsub(/"/, "\\\"", $0)
		printf "\"%s\"", $0
	}
}
END {
	if (is_array) {
		printf "]"
	}
	print "}}"
}'

Test Jumbo Frames / MTU 9000

Linux:

ping -M do -s 8972 xxx.xxx.xxx.xxx

OSX/BSD:

ping -D -s 8184 xxx.xxx.xxx.xxx

Windows:

ping -f -l 9000 xxx.xxx.xxx.xxx

Example results on Linux

If you’ve forgotten to enable jumbo frames/9k MTU on your client device you’re sending the ping from:

PING xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx): 8184 data bytes
ping: sendto: Message too long

If you have enabled jumbo frames on your client but not the destination (or a switch in between):

PING xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx): 8184 data bytes
Request timeout for icmp_seq 0

If you’ve done everything righ:

PING xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx): 8184 data bytes
8192 bytes from xxx.xxx.xxx.xxx: icmp_seq=0 ttl=128 time=0.714 ms

WebDAV with cURL

Assuming the following Data:

  • Webdav URL: http://example.com/webdav
  • Username: user
  • Password: pass

Actions

Reading Files/Folders

curl 'http://example.com/webdav'

Creating new Folder

curl -X MKCOL 'http://example.com/webdav/new_folder'

Uploading File

curl -T '/path/to/local/file.txt' 'http://example.com/webdav/test/new_name.txt'

Renaming File

curl -X MOVE --header 'Destination:http://example.org/webdav/new.txt' 'http://example.com/webdav/old.txt'

Deleting Files/Folders

File:

curl -X DELETE 'http://example.com/webdav/test.txt'

Folder:

curl -X DELETE 'http://example.com/webdav/test'

List Files in a Folder

curl -i -X PROPFIND http://example.com/webdav/ --upload-file - -H "Depth: 1" <<end
<?xml version="1.0"?>
<a:propfind xmlns:a="DAV:">
<a:prop><a:resourcetype/></a:prop>
</a:propfind>
end

Continue reading WebDAV with cURL