Bonus: grep for literal strings
štvrtok 22. októbra 2020
utorok 20. októbra 2020
How to analyze active cron jobs in CentOS 7
sudo cat /var/log/cron | cut -d ' ' -f 6- | sort | uniq -c | sort -nr
streda 14. októbra 2020
Statistical analysis of MySQL/MariaDB slow queries
One-liner:
sudo grep -e '^select' -e '^insert' -e '^update' -e '^delete' /srv/data/mysql/mysql_slow.log | cut -d ' ' -f 1-3 | sort | uniq -c | sort -nr | head
utorok 13. októbra 2020
How to extract raw value from JSON and cut it into pieces by size
Sample data:
{
"var_name1": {},
"var_name2": "string",
"var_name3": "long string",
"var_name4": 15
}
Fill Bash variable with extracted long string raw value from JSON:
VAR_NAME=`cat file.json | jq --raw-output '.var_name3'`
Then reference "chunks" of data using Bash variable index modifiers, e.g. by 255 characters:
- ${VAR_NAME:0:255}
- ${VAR_NAME:255:255}
- ${VAR_NAME:510:255}
- ${VAR_NAME:765:255}
- ${VAR_NAME:1020:255}
VAR_NAME=`cat file.json | jq --raw-output '.var_name3'` ; echo $VAR_NAME ; echo ${VAR_NAME:0:255} ; echo ${VAR_NAME:255:255} ; echo ${VAR_NAME:510:255} ; echo ${VAR_NAME:765:255} ; echo ${VAR_NAME:1020:255}
piatok 9. októbra 2020
utorok 29. septembra 2020
How to configure service principal for automated / scripted logins to Azure CLI
Steps:
- (check permissions)
- Azure Active Directory (AD) (AAD) level
- Azure Subscription level
- app registration
- AAD > App registrations > New registration
- get tenant (directory) ID and app (client) ID
- configure authentication ( (select app) > Certificates & secrets )
- certificate-based (> Certificates > Upload certificate)
- password-based (> Client secrets > New client secret)
- app role assignment
- Subscriptions > (select) > Access control (IAM) > Add role assignment
- (configure access policies on resources)
Using Azure portal:
https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal
Using Azure CLI:
https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli
Login via Azure CLI (password-based):
az login --service-principal --tenant TENANT_ID --username APP_ID --password PASSWORDLogin via Azure CLI (certificate-based):
az login --service-principal --tenant TENANT_ID --username APP_ID --password /path/to/certOther sign-in options:
https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli
How to commit & push local changes to separate (new) Git branch
git checkout -b new-branch
# more files can be added in this step too, wildcards supported
git add /path/to/locally/changed/file
git commit -m "commit message"
git show-branch
git push origin new-branch
Inspired by https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging.