確認憑證到期日期

DOMAIN=tgis.tw
date --date="$(echo | openssl s_client -showcerts -servername ${DOMAIN} -connect ${DOMAIN}:443 2>/dev/null | openssl x509 -inform pem -noout -enddate | awk -F '=' '{print $NF}'  )" +%s

修復VCenter Log Disk Exhaustion on vc 錯誤

參考: https://kb.vmware.com/s/article/2143565

輔助指令

df -h |awk '0+$5 >= 78 {print}'
du --max-depth=1 | sort -n -r  | head -n 20

修復指令

cp /usr/lib/vmware-sso/vmware-sts/webapps/ROOT/WEB-INF/classes/log4j2.xml /usr/lib/vmware-sso/vmware-sts/webapps/ROOT/WEB-INF/classes/log4j2.bak
sed -i 's/size=\"50 MB\"/size=\"10 MB\"/g' /usr/lib/vmware-sso/vmware-sts/webapps/ROOT/WEB-INF/classes/log4j2.xml
sed -i 's/max=\"10\"/max=\"3\"/g' /usr/lib/vmware-sso/vmware-sts/webapps/ROOT/WEB-INF/classes/log4j2.xml

cd /storage/log/vmware/sso/

rm localhost_access_log.*
rm vmware-identity-sts.*
rm vmware-identity-sts-perf.*
rm *2020*
rm *2021*

service vmware-stsd restart

git 範例

git 分支, 合併, tag 之範例

# 建立 develop branch
git branch develop
git checkout develop
git branch

for t in {1..5};
do
  TAG=v0.${t}
  FEATURE=feature/${TAG}

  # 建立 feature branch
  git branch ${FEATURE}
  git checkout ${FEATURE}
  git branch

  # commit 5個版本
  for i in {1..5};
  do
    data=$(printf "${FEATURE}-%03d" $i)
    echo $data >> history.txt
    history=$(cat history.txt)
    printf "# Test\n## Version\n${data}\n## History\n\`\`\`\n${history}\n\`\`\`\n" > readme.md
    git add .
    git commit -m "version: ${data}"
    git push -u origin ${FEATURE}
  done
  git branch

  # 切換develop
  git checkout develop
  git branch

  # 合併
  git merge --no-ff -m "合併(from ${FEATURE} to develop)" ${FEATURE}
  git push -u origin develop

  # 刪除分支
  git branch -d ${FEATURE}
  git push -u origin :${FEATURE}
  git push -u origin develop

  # 切換到master
  git checkout master
  git branch

  # 合併
  git merge --no-ff -m "合併(from 合併 to master)" develop
  git push -u origin master

  # 建立release
  git tag ${TAG}
  git tag -l
  git push origin ${TAG}
done

php發送log至syslog server

範例

<?php
function BSD_Syslog($msg,$severity=7, $program="php-test",$remote_ip='127.0.0.1',$remote_port=514){
  date_default_timezone_set('Asia/Taipei');
  $facility=5;
  $severity=7;
  $PRI = $facility*8+$severity;
  $HEADER=date('M d H:i:s ') . $program;
  $syslog_message = "<{$PRI}>{$HEADER} {$msg}";
  $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  socket_sendto($sock, $syslog_message, strlen($syslog_message), 0, $remote_ip, (int)$remote_port);
  socket_close($sock);
}
BSD_Syslog("test: ".rand()%10000);

其中facility的值如下:

         Code

          0             kernel messages
          1             user-level messages
          2             mail system
          3             system daemons
          4             security/authorization messages
          5             messages generated internally by syslogd
          6             line printer subsystem
          7             network news subsystem
          8             UUCP subsystem
          9             clock daemon
         10             security/authorization messages
         11             FTP daemon
         12             NTP subsystem
         13             log audit
         14             log alert
         15             clock daemon (note 2)
         16             local use 0  (local0)
         17             local use 1  (local1)
         18             local use 2  (local2)
         19             local use 3  (local3)
         20             local use 4  (local4)
         21             local use 5  (local5)
         22             local use 6  (local6)
         23             local use 7  (local7)

severity的值如下:


         Code
          0       Emergency: system is unusable
          1       Alert: action must be taken immediately
          2       Critical: critical conditions
          3       Error: error conditions
          4       Warning: warning conditions
          5       Notice: normal but significant condition
          6       Informational: informational messages
          7       Debug: debug-level messages

在macos使用qemu安裝windows

安裝Qemu

brew install qemu

建立硬碟

qemu-img create -f raw ~/qemu/disk.img 20G
qemu-img info ~/qemu/disk.img

修正Qemu錯誤

原生安裝好的qemu執行虛擬機時,會出現qemu-system-x86_64: Error: HV_ERROR的錯誤,
修正方式如下:

# 參考 https://stackoverflow.com/a/64993771/4802467
cat << EOF > app.entitlements
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.hypervisor</key>
    <true/>
</dict>
</plist>
EOF
md5 $(which qemu-system-x86_64)
codesign -s - --entitlements app.entitlements --force $(which qemu-system-x86_64)
md5 $(which qemu-system-x86_64)
rm -f app.entitlements

開啟虛擬機

qemu-system-x86_64 \
  -m 4G \
  -vga virtio \
  -display default,show-cursor=on \
  -usb \
  -device usb-tablet \
  -machine type=q35,accel=hvf \
  -smp 2 \
  -drive file=/Users/slanla/qemu/disk.img,index=0,format=raw,if=virtio \
  -drive file=windows.iso,index=1,media=cdrom \
  -drive file=virtio-win-drivers-20120712-1.iso,index=2,media=cdrom \
  -cpu Nehalem

資源下載

virtio-win-drivers-20120712-1.iso

透過run-avrdude燒錄Arduino Yun

由於不小心在上一支程式用太多記憶體(接近99%)
造成Arduino Yun無法透過IDE Upload程式了
原本打算用 Arduino as ISP方式用另外一台Arduino Yun來燒錄.
但是試不出來.

後來在論壇上( https://forum.arduino.cc/index.php?topic=355657.0 )看到可以用run-avrdude來進行燒錄
因此就先用Blink建立最簡單的hex後,
再把檔案傳到Arduino上.
接著ssh進去yun後,透過下列指令進行燒錄

merge-sketch-with-bootloader.lua Blink.ino.hex
run-avrdude Blink.ino.hex

如果只是單純使用run-avrdude,也是可以燒錄.
但是IDE依然無法燒錄.
後來用merge-sketch-with-bootloader.lua對hex檔案天加入了bootloader後.
就可以讓IDE燒錄了.

php 常用函式

mk_dir: 遞迴建立資料夾
ls: 遞迴取得所有檔案清單(不含目錄)

function mk_dir($dir, $mode = 0777){
  if (is_dir($dir) || @mkdir($dir,$mode)) return TRUE;
  if (!mk_dir(dirname($dir),$mode)) return FALSE;
  return @mkdir($dir,$mode);
}

function ls($path,$loop=true){
  $items=[];
  $files=scandir($path);
  foreach($files as $item){
    if($item!="." && $item!=".."){
      $file="${path}/${item}";
      if(is_dir($file) && $loop){
        $items=array_merge($items,ls($file));
      }
      else if(is_file($file)){
        $items[]=($file); //realpath
      }
    }
  }
  return $items;
}

擋廣告神器 Adguard Home 架設

mkdir -p $PWD/adguardhome/workdir
mkdir -p $PWD/adguardhome/confdir
docker rm -f adguardhome
docker run \
  -d \
  --name=adguardhome \
  --restart=always \
  -v $PWD/adguardhome/workdir:/opt/adguardhome/work \
  -v $PWD/adguardhome/confdir:/opt/adguardhome/conf \
  -p 53:53/tcp \
  -p 53:53/udp \
  -p 67:67/udp \
  -p 68:68/tcp \
  -p 68:68/udp \
  -p 80:80/tcp \
  -p 443:443/tcp \
  -p 853:853/tcp \
  -p 3000:3000/tcp \
  adguard/adguardhome