Posts in category “Linux”

ubuntu 20.04 手工生成通配符ssl证书

其实很简单,但因为网上有流传很广的教程并不适用于最新的 ubuntu 20.04,造成我也走了一点弯路。 certbot-auto 官方已停止维护,但网上广为流传的教程仍然推荐使用 certbot-auto 来生成证书。这是问题的根源。正确的姿势是这样的

sudo apt install certbot
sudo certbot certonly --manual -d *.yourdomain.com -d youdomain.com --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory

照提示一步一步来就好了。是不是超级简单?

switch case in bash script

, change the first letter of the value of the variable to lowercase, ,, change the value of the whole variable to lower case.

$ test='HELLO'
$ echo $test
HELLO
$ echo ${test,}
hELLO
$ echo ${test,,}
hello
$ test=${test,,}
$ echo ${test^}
Hello
$ echo ${test^^}
HELLO

A bash script to keep two git branch identical.

#!/bin/bash

git push
currentbranch=`git branch --show-current`
if [ "${currentbranch}" == "local" ]; then
   git checkout develop
   git merge local
   git push
elif [ "${currentbranch}" == "develop" ]; then
   git checkout local
   git merge develop
   git push
fi
git checkout $currentbranch

Don't ask why I wrote this foolish script. I have to do it 😀

Attention: the first definition is used when you have more than one same host label in your .ssh/config file

I originally thought the later should be used. I was wrong.

Bash script for checking telnet service status


cat monitor.sh 
#!/bin/bash
source /etc/profile
cd /home/koala/Vagrant/windows-server-2019
(echo > /dev/tcp/192.168.178.220/23) > /dev/null 2>&1
if [ $? -ne 0 ]; then
  vagrant halt
  vagrant up
fi