bash-fu

Quick and easy self signed ssl certificate

In many environments you can use ssl encryption, and you may skip the encryption because generating a cert or getting a lets encrypt cert would add more time to the thing your are working on. To overcome this security issue I wrote a small script to create a crt and key file. selfsigned.sh #!/bin/bash # fast ssl cert without ca ENDPOINT=$1 openssl genrsa -out $ENDPOINT.key 2048 openssl req -new -x509 -key $ENDPOINT.

Backup all databases on a plesk server

This is not the fastest not the safest and not the most eficient, but it does work. and unless you have a realy bussy database this is a pretty oke way to backup your database. It uses mysqldump and the internal plesk credentials so no need to type passwords at all. It can ofcourse be used on any other mysql server as long as you set the right credentials. #! /bin/bash # aapjeisbaas.

Remote diff over ssh

Want to do a diff on a local and remote file, or on 2 remote files. Here is a small trick # Local and remote diff diff file <(ssh remote 'cat file') # Or both are on remote servers diff <(ssh remote1 'cat file') <(ssh remote2 'cat file') I use this a lot when a ansible –check run tells me there is a diff and want to know what I will be overwriting.

Run a script when load is too high

This is a small script that can check if server load is too high and start another script. It is NOT best practice to fix a problem like this but it can get you trough the nights while developers work on the code problem. I called my script /usr/local/bin/damnnastycheck.sh it runs every minute from /etc/crontab yhe only requirement is BashCalc (bc) #!/bin/bash high=8.1 if [ $(echo $(cat /proc/loadavg | awk '{print $1}')'>'$high | bc -l) == "1" ]; then echo "high load, running fix" /usr/local/bin/damnnastyfix.

Find broken RAM DIMM in server

A broken ram module is pretty annoying in itself but trying to find it by trial and error is even worse. This simple command shows the locations of the active dimms in the system. Run it and find the missing one, in this case: CPU#0Channel#0_DIMM#1 [root@machine ~]# cat /sys/devices/system/edac/mc/mc*/csrow*/ch*_dimm_label CPU#0Channel#0_DIMM#0 CPU#0Channel#1_DIMM#0 CPU#0Channel#2_DIMM#0 CPU#0Channel#1_DIMM#1 CPU#0Channel#2_DIMM#1 CPU#1Channel#0_DIMM#0 CPU#1Channel#1_DIMM#0 CPU#1Channel#2_DIMM#0 CPU#1Channel#0_DIMM#1 CPU#1Channel#1_DIMM#1 CPU#1Channel#2_DIMM#1 [root@machine ~]# Or: [root@machine ~]# cat /sys/devices/system/edac/mc/mc*/dimm*/dimm_label