2021/10/12
about the shell until keyword, which is equivalent to while !.
about the shell until keyword, which is equivalent to while !.
to run terraform output $output_name to print a named output
You can use journalctl -u ${service_name}.service --since ${time:-today} to view the logs of a systemd service: https://www.digitalocean.com/community/tutorials/how-to-use-journalctl-to-view-and-manipulate-systemd-logs
tar -ztvf file.tar.gz will list the files in tar.gz
how to check the last apt update time:
last_update="$(stat --format=%Y /var/cache/apt/pkgcache.bin)"
that sudo can be configured with the visudo command and that sudo can produce audit logs.
See https://www.sudo.ws/posts/2022/05/sudo-for-blue-teams-how-to-control-and-log-better/
that there’s an Element.closest(selector) method, which means you can run this function to set the url to the closest link to an element:
((el) => {
let id = el.closest("[id]")?.id;
if (!id) return;
else location.hash = id;
})($0);
that you can use
SELECT /*...*/
FROM one_table
JOIN other_table
USING (common_column)
as shorthand for one_table.common_column = other_table.common_column.
See https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM
That you can call time(1) to time how long a shell command takes, like so:
; time terraform fmt -write=true -recursive .
# terraform fmt -write=true -recursive . 0.10s user 0.23s system 24% cpu 1.377 total
that gzip(1), by default, includes file mtimes. The flag to prevent gzip from zipping non-deterministically is gzip --no-name or gzip -n.
That sql has assertions:
CREATE ASSERTION <Constraint name>
CHECK (search condition)
[ <constraint attributes> ]
see https://crate.io/docs/sql-99/en/latest/chapters/20.html#create-assertion-statement.
h/t https://www.scattered-thoughts.net/log/0024/ for bringing that to my attention.
Also, from the weekend: in postgres, at least, you can call TABLE :table_name; directly to SELECT * FROM :table_name;
Also: how to look up a domain name from an ip:
reverse_ip_lookup() {
ip_address="$1"
dig -x $ip_address +noall +answer
}
Also: how to audit AWS VPC flow logs from CloudWatch Log Insights: use the example queries in the right sidebar.
Also: python can execute .zip files directly, like so:
:; echo 'print("Hello, World!")' > __main__.py
:; zip hello-world.zip __main__.py
:; python3 ./hello-world.zip
## Hello, World!
h/t https://pradeepchhetri.xyz/til/pythonzip/ for pointing that out.
That pg_dumpall exists.
That you need to use pg_dumpall to dump tablespaces, roles, and subscriptions.
That pg_dumpall will dump the postgres role by default, causing resultant dump to fail to restore.
Fortunately, I’m able to grep -ve '^CREATE ROLE postgres
that in bash and zsh, you can put a newline in a variable like so:
newline=$'\n'
echo ">>>${newline}<<<"
learned from: https://stackoverflow.com/a/4456399/6571327
That you can call docker compose kill to kill all docker-compose containers
That there’s a timeout shell command in gnu coreutils: https://man7.org/linux/man-pages/man1/timeout.1.html
that you can lsblk to list the block devices that the OS knows about without sudo.
that you can sudo growpart to increase a partition size without restarting the machine.
That terraform plan -detailed-exitcode exists: 0 means no diff, 1 means error, 2 means a diff exists.
Also, that you can print the source code of a bash function like so:
print_fn_src() { declare -f "$1"; }
That BSD arch command found on Macs also supports a -${arch} flag for running universal binaries.
That you need ato git add a flake.nix for the flake’s contents to start to work with nix develop
This is needed because Nix flakes respects gitignores. If you don’t add things to the git staging area, git doesn’t know about the files at all, and Nix flakes can’t know if it should ignore them. – https://xeiaso.net/blog/nix-flakes-go-programs
that “truecolor” support in shells is detected with the $COLORTERM env var
That there’s a Linux command to do sql-like JOINs of lines in files, possibly based on a field in each line: join(1)
That POSIX shell has configuration option, set -a or set -o allexport that exports all assigned variables.
This simplifies using .env files in .envrc files:
# evaluate a .env file, if it exists
if [ -f .env ]; then
set -a # assigning a variable exports the variable
# shellcheck disable=SC1091
source .env
set +a
fi
That JS has a String.raw template literal tag function that unescapes escape sequences in a backtick-string:
String.raw`\t\r\n` // => "\\t\\r\\n"
which -a python # shows all matches on $PATH type python # checks if a builtin/alias/fn/exe