快速在遠端執行本地 bash file
1 |
ssh user@remote 'bash -s' < local.sh |
快速在遠端執行本地 bash file
1 |
ssh user@remote 'bash -s' < local.sh |
1 |
locale -a |
1 |
LANG=zh_TW.UTF-8; export LANG |
基本說明:
split(string, array[, field separator]) : 字串,變數名稱,分割符號(預設當前FS)
ex: 取出第二個元素,再使用":" 分割字串存成陣一列 ar ,再print 出 ar 第二個元素
1 2 |
echo "123:456 789:abc" | awk '{ split($2,ar,":"); print ar[2]}' abc |
substr(string,p[,n]): 字串,從p開始,長度為n
ex: 使用 substr 取出第二個元素, 從第3個字元開始,取1個字元
1 2 3 4 |
echo "1234 5678 9abc" | awk '{print substr($2,3)}' 78 echo "1234 5678 9abc" | awk '{print substr($2,3,1)}' 7 |
length([string]): 返回字串長度,預設為$0
ex:
1 2 3 4 |
echo "1234 5678 9abc" | awk '{print length()}' 14 echo "1234 5678 9abc" | awk '{print length($1)}' 4 |
綜合應用
處理nginx log
1.每10秒的連線計數
1 |
cat nginx.log | awk '{ print substr($4,14,7)}' | sort | uniq -c |
2.統計IP 使用 class C
1 |
cat nginx.log | awk '{ split($1,ipar,".") ; print ipar[1]"."ipar[2]"."ipar[3]".0"}' | sort | uniq -c |
在nomachine player 程式停在 main page 時, 大量的 mdsn 封包進行 broadcast , 導至內網嚴重掉包
1 |
apt install conky curl -y |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
vim /etc/conky/conky.conf -- vim: ts=4 sw=4 noet ai cindent syntax=lua conky.config = { alignment = 'top_right', background = false, border_width = 0.1, cpu_avg_samples = 4, default_color = 'white', default_outline_color = 'gray', default_shade_color = 'black', draw_borders = true, draw_graph_borders = false, draw_outline = false, draw_shades = false, use_xft = true, font = 'DejaVu Sans Mono:size=11', gap_x = 10, gap_y = 45, minimum_height = 5, minimum_width = 5, net_avg_samples = 2, double_buffer = true, out_to_console = false, out_to_stderr = false, extra_newline = false, own_window_colour = '000000', own_window_class = 'Conky', own_window = true, own_window_transparent = false, own_window_argb_value = 90, own_window_argb_visual = true, own_window_type = 'desktop', own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager', stippled_borders = 0, update_interval = 1, uppercase = false, use_spacer = 'none', show_graph_scale = false, show_graph_range = false } conky.text = [[ #${image ~/.face -p 180,5 -s 70x70 -f 86400}${image ~/.pacman -p 20,9 -s 60x60 -f 86400} ${font Latin Modern Mono Caps:bold:size=14}${alignc}${color 00ffae}$nodename ${font Noto Sans:bold:size=8}${alignc}${desktop_name} ${desktop}/$desktop_number ${font Noto Sans:bold:size=8}${alignc} ${exec hostnamectl | grep System | cut -c21-40} #${alignc} ${exec hostnamectl | grep Architecture | cut -c7-30} #${alignc} ${exec hostnamectl | grep Kernel | cut -c13-34} #${alignc} Conky PID: ${color red}${execi 15 pgrep -l conky | cut -d ' ' -f 1} ${font Entopia:bold:size=12}${color 33E9FF}PERFORMANCE ${hr 2}${font} ${offset 15}${color FFFDE2}System Uptime ${alignr}$color $uptime ${offset 15}${color FFFDE2}Frequency: ${alignr}${freq dyn} MHz ${offset 15}${color FFFDE2}RAM Usage:$color $mem${color0}/${color4}$memmax - $memperc% ${offset 15}${color FFFDE2}SWPA Usage:$color $swap${color0}/${color4}$swapmax - $swapperc% ${offset 15}${color yellow}${membar 5} ${offset 15}${color FFFDE2}CPU:$color ${cpu}% ${color yellow}${cpubar 5}${color FFFDE2} ${offset 15}${font}${color FFFDE2}Procs:$color $processes ${color FFFDE2}Run:$color $running_processes Temp: ${acpitemp}°C ${offset 15}Core 1 ${color ff9300}${cpubar cpu1 6}${color FFFDE2} ${offset 15}Core 2 ${color ff7300}${cpubar cpu2 6}${color FFFDE2} #${offset 15}Core 3 ${color ff4300}${cpubar cpu3 6}${color FFFDE2} #${offset 15}Core 4 ${color ff1300}${cpubar cpu4 6}${color FFFDE2} ${font Entopia:bold:size=12}${color green}NETWORK ${hr 2}${font} ${offset 15}${color FFFDE2}Ext IP Addr ${color 33E9FF}${alignr}${execi 300 curl -s ifconfig.co } #${exec cat /root/myip.txt} ${offset 15}${color FFFDE2}GateWay:${color 33E9FF}${alignr}${gw_ip} ${offset 5}${font Entopia:bold:size=12}${color orange}LAN ${stippled_hr 1} ${offset 15}${font}${color FFFDE2}IPv4 Addr ${color 33E9FF}${alignr}${addr eth0} ${offset 15}${color green}${font}▼ $color${downspeed eth0} ${alignr}${color green}▲ $color${upspeed eth0} ${offset 15}${font}${color}DOWN ${downspeedgraph eth0 32,0 324D23 77B753} ${offset 15}${font}${color}UP ${upspeedgraph eth0 32,0 104E8B ffff00} ${offset 5}${font Entopia:bold:size=12}${color orange}${wireless_essid wlo1} ${stippled_hr 1} #${offset 15}${color FFFDE2}${font}WiFi ${alignr}${wireless_link_qual_perc #wlo1}%(${wireless_link_qual wlo1}/${wireless_link_qual_max wlo1}) ${color 33E9FF}${addr wlo1} #${offset 15}${font}${color green}▼ $color${downspeed wlo1} ${alignr}${color green}▲ $color${upspeed wlo1} #${offset 15}${font}${color}DOWN ${downspeedgraph wlo1 32,0 324D23 77B753} #${offset 15}${font}${color}UP ${upspeedgraph wlo1 32,0 104E8B ffff00} ${font Entopia:bold:size=12}${color 33E9FF}PROCESSES ${hr 2} ${offset 15}${font Noto sans:size=9}${color EDE0FF}Name ${alignr}PID CPU% MEM% ${offset 15}${color FF7878}${top name 1} ${alignr}${top pid 1} ${top cpu 1} ${top mem 1} ${offset 15}${color FF7878}${top name 2} ${alignr}${top pid 2} ${top cpu 2} ${top mem 2} ${offset 15}${color FF7878}${top name 3} ${alignr}${top pid 3} ${top cpu 3} ${top mem 3} ${offset 15}${color FF7878}${top name 4} ${alignr}${top pid 4} ${top cpu 4} ${top mem 4} ${offset 15}${color FF7878}${top name 5} ${alignr}${top pid 5} ${top cpu 5} ${top mem 5} ${offset 15}${color FF7878}${top name 6} ${alignr}${top pid 6} ${top cpu 6} ${top mem 6} ${offset 15}${color FF7878}${top name 7} ${alignr}${top pid 7} ${top cpu 7} ${top mem 7} ${offset 15}${color FF7878}${top name 8} ${alignr}${top pid 8} ${top cpu 8} ${top mem 8} ${offset 15}${color FF7878}${top name 9} ${alignr}${top pid 9} ${top cpu 9} ${top mem 9} ${font Entopia:bold:size=12}${color 7cfc00} DISKINFO ${hr 2} ${offset 15}${color 7cfc00}disk : ${diskio} ${offset 15}${color 7cfc00}Disk I/O: ${offset 15}${diskiograph 32,0 ff7300 ff7300} ${font Entopia:bold:size=12}${color 33E9FF}END ${hr 2}${font} ]] |
1 |
conky -c /etc/conky/conky.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
vim ~/.config/autostart/conkystartup.desktop [Desktop Entry] Encoding=UTF-8 Version=0.9.4 Type=Application Name=conkystartup Comment=conky Exec=/usr/bin/conky OnlyShowIn=XFCE; RunHook=0 StartupNotify=false Terminal=false Hidden=false |
1 2 3 4 |
free -m total used free shared buff/cache available Mem: 961 535 81 0 344 252 Swap: 2047 371 1676 |
1 2 3 4 5 6 |
#pagecache echo 1 > /proc/sys/vm/drop_caches #dentries + inodes echo 2 > /proc/sys/vm/drop_caches #pagecache + dentries + inodes echo 3 > /proc/sys/vm/drop_caches |
1 2 3 |
# 執行前需確認mem 的空間足夠接收 swap 所釋放出來的空間 swapoff -a swapon -a |
1 2 3 |
vim /etc/sysctl.conf vm.swappiness=10 sysctl -p |
1 |
apt install lm-sensors |
檢查相容的傳感器
1 |
sensors-detect [--auto] |
檢視溫度
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
sensors #output iwlwifi_1-virtual-0 Adapter: Virtual device temp1: +66.0°C pch_cometlake-virtual-0 Adapter: Virtual device temp1: +86.0°C nvme-pci-0200 Adapter: PCI adapter Composite: +63.9°C (low = -5.2°C, high = +79.8°C) (crit = +84.8°C) ucsi_source_psy_USBC000:001-isa-0000 Adapter: ISA adapter in0: 0.00 V (min = +0.00 V, max = +0.00 V) curr1: 0.00 A (max = +0.00 A) coretemp-isa-0000 Adapter: ISA adapter Package id 0: +81.0°C (high = +80.0°C, crit = +100.0°C) Core 0: +81.0°C (high = +80.0°C, crit = +100.0°C) Core 1: +71.0°C (high = +80.0°C, crit = +100.0°C) Core 2: +80.0°C (high = +80.0°C, crit = +100.0°C) Core 3: +69.0°C (high = +80.0°C, crit = +100.0°C) |
1 2 3 4 5 6 |
apt update && apt -y upgrade apt install git build-essential cmake libuv1-dev libssl-dev libhwloc-dev git clone https://github.com/xmrig/xmrig.git sed -i 's/=\s1/= 0/g' xmrig/src/donate.h mkdir xmrig/build && cd xmrig/build && cmake .. make -j$(nproc) |
https://config.xmrig.com/
./xmrig
1 2 3 4 5 6 |
#清空 HISTFILE 變數內容,則登出時不會記錄 unset HISTFILE or #設定history 的size 為0 ,跟上面的差別是下history 指令時為空 HISTSIZE=0 |
1 2 |
history -c history -w |
export HISTTIMEFORMAT='%F %T '
目的:
載入 squid access.log 輸出到遠端 rsyslog server , 使用local7
squid : /etc/rsyslog.d/squid.conf
1 2 3 4 5 |
$ModLoad imfile #provides support for file logging input( type="imfile" File="/var/log/squid/access.log" Tag="squid" Severity="info" Facility="local7" Ruleset="logsrv") ruleset(name="logsrv"){ action( type="omfwd" Target="172.16.1.1" Port="514" Protocol="udp") } |
rsyslog server : /etc/rsyslog.d/squid_collect.conf
1 2 3 4 |
$template SquidMsg,"%msg:2:$% %fromhost-ip%\n" if $syslogfacility-text == 'local7' and $programname == 'squid' then { action(type="omfile" file="/var/log/squid/access.log" template="SquidMsg") } |
syslogfacility-text 對應到 Facility
programname 對應到 Tag