Often times we need the current date (and time) when scripting inside bash or other shells. For example when creating a backup file or writing to a log.
[Read More]Navigate to Script Directory
Often times when writing scripts I want to reference files in the same directory, but keep the script portable in case it is part of a git repository being checked out somewhere else or just the folder getting moved.
[Read More]CLI fuzzy search
I often whish to search through large bodies of text, like my knowledge base or source code repositories, from the command line.
I use fuz for this and I’m quite happy with it.
I also have it aliased to my knowledge base folder for even easier searching.
alias search="fuz -p /path/to/knowledge-base/"
WSL2 & Keychain
The problem
If you use ssh-agent with an encrypted ssh key it does not persist when you open a new terminal window.
The solution
Use keychain
instead.
- Install
sudo apt install keychain
- Add to your shells rc file, eg.
.bashrc
or.zshrc
# Repeat this line for all keys you want to unlock and use this way /usr/bin/keychain -q --nogui $HOME/.ssh/id_rsa source $HOME/.keychain/wsl-sh
- Unlock your keys on shell startup and enjoy
Resolve .local Through Nameserver With Netplan
When using netplan it is easy to force .local DNS requests to go to you nameservers instead of being only resolved locally (the default and standard).
This also works with all other strange .WHATEVER domains you may have lying around in your organization.
Snippet from netplan configuration:
nameservers:
addresses:
- X
- Y
search:
- local
- myotherstupiddomain
MongoDB Logrotate
Show all active user cron jobs on a system
Debian/Ubuntu
grep -vH "#" /var/spool/cron/crontabs/*
RedHat/Centos/Rocky
grep -vH "#" /var/spool/cron/*
DNS Resolution Everywhere
How SELinux screws with scripts when run over VMware Tools
SELinux by default prohibits certain things from working through VMware tools (Ansible connection or plain API).
This can be solved two ways:
- Disabling SELinux: BAD, but easy
- Writing a custom SELinux policy: complicated but more secure
Note: Adding/Changing this policy through a VMware tools connection is thankfully possible
Example policy
This policy is the base for a VMware tools policy and allows entering the rpm context (yum).
module custom-vmtools 1.0;
require {
type rpm_script_t;
type vmtools_unconfined_t;
class process transition;
}
#============= vmtools_unconfined_t ==============
allow vmtools_unconfined_t rpm_script_t:process transition