https://gist.github.com/iiidefix/2d170a9cbe92974b25fdd1f88adb2c96
Tag Archives: bash
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 "}}"
}'
Unifi USG Radius default vlan
on USG
/config/scripts/post-config.d/radius_default_vlan.sh
#!/bin/bash # radius_default_vlan.sh # This script goes in /config/scripts/post-config.d if [[ -z "$1" ]] ; then echo "* * * * * root /config/scripts/post-config.d/radius_default_vlan.sh cron" > /etc/cron.d/radius_default_vlan exit 0 fi if grep -q "DEFAULT Auth-Type" "/etc/freeradius/users" ; then exit 0 fi cat >> /etc/freeradius/users <<EOF DEFAULT Auth-Type := Accept Tunnel-Type = 13, Tunnel-Medium-Type = 6, Tunnel-Private-Group-Id = 1 EOF service freeradius restart
install
chmod +x /config/scripts/post-config.d/radius_default_vlan.sh /config/scripts/post-config.d/radius_default_vlan.sh
remove
rm /etc/cron.d/radius_default_vlan rm /config/scripts/post-config.d/radius_default_vlan.sh
bash DNSDIST dashboard
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