2022年4月28日 星期四

bash script 自動背景執行

 #!/bin/bash

echo pid=$$
(kill -STOP $$;kill -CONT $$) &
while true; do echo pid=$$;sleep 1;done

檢查 /var/log/lastlog

#!/bin/bash
# /var/log/lastlog > 1g
_debug=;

mfile=/var/log/lastlog
archive_dir=/var/log

_f0=$(echo $0|tr \/ _)-$(echo ${*}|md5sum|awk '{print $1}');
exec 100> /tmp/${_f0}.lock
flock -n 100 || exit 1

echo $$ $(date +%Y%m%d-%H%M%S) $0 $* >&100

inotifywait -m ${mfile} |while read dir action file;
do [ -z "$file" ]&&_f=$dir||_f=${dir}/${file};
[ -z "$_debug" ]|| echo debug: $dir $action $file f=$_f;
a_f=$(basename $mfile).$(date +%Y%m%d-%H%M%S);
[ -z "$(ls -lh $_f|awk '{ print $5}'|grep G)" ]||{ lastlog >${archive_dir}/$a_f; :>$mfile; [ -z "$_debug" ]||echo "run..."; }
done;


#!/bin/bash
_lastlog=/var/log/lastlog
_lastarchive=/var/log/lastlog

[ -f $_lastlog ]||exit 0;
[ -z "$(ls -lh $_lastlog|awk '{print $5}'|grep G)" ]&& exit 0;
lastlog > ${_lastarchive}.$(date +%Y%m%d-%H%M%S);
:>$_lastlog;

2022年4月27日 星期三

debian 11 安裝 incron

 Debian 11 bullseye  廢棄 incron,以 systemd.path 取代

2022年4月26日 星期二

xfce4 桌面設定 預設不顯示 垃圾筒、home目錄

編輯 /usr/share/desktop-base/profiles/xdg-config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml

<channel> 加入

<property name="desktop-icons" type="empty">
    <property name="file-icons" type="empty">
      <property name="show-trash" type="bool" value="false"/>
      <property name="show-filesystem" type="bool" value="false"/>
      <property name="show-home" type="bool" value="false"/>
    </property>
  </property>

2022年4月25日 星期一

Debian 11 安裝最新版本 Glusterfs

apt install -y gpg
wget -O - https://download.gluster.org/pub/gluster/glusterfs/9/rsa.pub | apt-key add -
DEBID=$(grep 'VERSION_ID=' /etc/os-release | cut -d '=' -f 2 | tr -d '"')
DEBVER=$(grep 'VERSION=' /etc/os-release | grep -Eo '[a-z]+')
DEBARCH=$(dpkg --print-architecture)
echo deb https://download.gluster.org/pub/gluster/glusterfs/LATEST/Debian/${DEBID}/${DEBARCH}/apt ${DEBVER} main > /etc/apt/sources.list.d/gluster.list

apt update
apt install glusterfs-server

symbol lookup error: gluster: undefined symbol: use_spinlocks

 檢查 Glusterfs 相關套件版本

2022年4月22日 星期五

Linux Debian bcache 摘要

安裝
apt install bcache-tools

建立資料碟(必須大於快取碟)
make-bcache -B /dev/sdx1

建立快取碟(ram disk 不適用)
make-bcache --block 4k --bucket 2M -C /dev/sdy1

指定 資料碟的快取碟
echo $(bcache-super-show /dev/sdy1|grep cset.uuid|awk '{print $2}') >/sys/block/bcache0/bcache/attach
make-bcache -B /dev/sda /dev/sdb -C /dev/sdc

查詢 bcache 運作狀態
cat /sys/block/bcache0/bcache/state
no cache: 沒有 cache 設備
clean: 正常,cache clean
dirty: 正常,cache 模式 writeback,cache 狀態 dirty
inconsistent: 有問題,cache 及 資料沒有同步

查詢cache 模式
cat /sys/block/bcache0/bcache/cache_mode
[writethrough] writeback writearound none

更改 cache 模式
echo writeback > /sys/block/bcache0/bcache/cache_mode

bcache 裝置顯示
/dev/bcacheN
/dev/bcache/by-uuid/UUID
/dev/bcache/by-label/LABEL

停用設備
echo 1 > /sys/block/sdX/sdX[Y]/bcache/stop

停止快取
echo 1 > /sys/block/sdX/sdX[Y]/bcache/detach

安全移除快取
echo <cache-set-uuid> > /sys/block/bcache0/bcache/detach

釋放已使用裝置
echo 1 > /sys/fs/bcache/<cache-set-uuid>/stop

重新載入 bcache 裝置
partprobe  (apt install parted)
echo /dev/sdX > /sys/fs/bcache/register
echo /dev/sdY > /sys/fs/bcache/register

Force flush of cache to backing device
echo 0 > /sys/block/bcache0/bcache/writeback_percent


相關檔案 /etc/tmpfile.d/bcache.conf
w /sys/block/bcache0/bcache/sequential_cutoff - - - - 1M
w /sys/block/bcache0/bcache/cache_mode        - - - - writeback