Linux ค้นหาไฟล์ที่เก่ากว่า 30 วันให้ลบออก
ใน Linux สามารถใช้คำสั่ง find เพื่อค้นหาและลบไฟล์ที่ เก่ากว่า 1 เดือน ได้ตามนี้
คำสั่ง:-
#find /path/to/folder -type f -mtime +30 -exec rm -f {} \;
/path/to/folder = โฟลเดอร์ที่คุณต้องการค้นหา (เช่น /var/log หรือ /mnt/backup)
-type f = เลือกเฉพาะไฟล์ (ไม่รวมโฟลเดอร์)
-mtime +30 = ไฟล์ที่ ถูกแก้ไขครั้งสุดท้ายมากกว่า 30 วัน (ประมาณ 1 เดือน)
-exec rm -f {} \; = ลบไฟล์ที่เจอทันที
ถ้าต้องการแค่ดูรายการไฟล์ (ไม่ลบ):
#find /path/to/folder -type f -mtime +30
Xsession: unable to start x session
Xsession: unable to start x session — “no /home/teee/.xsession” file no session manager , no windows manager ,and no terminal emulator found, abourting
ข้อความผิดพลาดนี้บอกว่า X ไม่สามารถเริ่มเซสชันได้เพราะ:
-
ไม่มีไฟล์
~/.xsession
-
ไม่มี session manager
-
ไม่มี window manager
-
ไม่มี terminal emulator
สาเหตุที่เป็นไปได้:
-
XFCE ยังไม่ได้ติดตั้งครบ
-
ไม่มี display manager หรือถูกตั้งค่าผิด
-
X11 พยายามเริ่มต้นจาก
.xsession
แต่ไม่มีการกำหนดค่า
วิธีแก้ไข
วิธีที่ 1: ตรวจสอบและติดตั้ง XFCE พร้อม X11 อย่างถูกต้อง
sudo apt update
sudo apt install xfce4 xfce4-goodies xorg lightdm
ระหว่างการติดตั้ง ถ้ามีคำถามเรื่อง Display Manager ให้เลือก lightdm
วิธีที่ 2: ตรวจสอบว่ามี session ของ XFCE ใน /usr/share/xsessions
ls /usr/share/xsessions
ควรเห็นไฟล์ชื่อประมาณ:
-
xfce.desktop
วิธีที่ 3:ตรวจสอบว่าติดตั้ง terminal emulator ด้วย
เช่น xfce4-terminal
หรือ xterm
:
sudo apt install xfce4-terminal xterm
เสร็จแล้วลอง Reboot ดู
Debian แก้ไขคำสั่งบูต GRUB ชั่วคราวเพื่อเข้าผ่าน shell
เลือกบรรทัดแรก (Debian GNU/Linux) แล้วกด e เพื่อ “edit”
หาบรรทัดที่ขึ้นต้นว่า:
linux /boot/vmlinuz-… root=UUID=… ro quiet
ลบ quiet ออก และ เพิ่ม:
linux /boot/vmlinuz-… root=UUID=… ro systemd.unit=multi-user.target
กด Ctrl + X หรือ F10 เพื่อบูตด้วยค่าที่คุณแก้ไข
Debian เปิดเครื่องเจอแต่ loopback interface
อาจเป็นไปได้ว่า interface จะ down อยู่ ให้ใช้คำสั่งครวจสอบ
#ip link show
#ip link set enp0s3 up
#dhclient enp0s3
Ubuntu แก้ไข motd
ปิดระบบ dynamic MOTD (ให้แสดงแค่ /etc/motd)
sudo chmod -x /etc/update-motd.d/*
sudo nano /etc/motd
วิธีการใช้งาน scrcpy เพื่อ mirror หน้าจอ samsung s24 บนเครื่อง mac
#ที่มือถือให้ทำการเปิด Developer Mode
1. ไปที่ settings > About phone > Software information >
กดย้ำๆที่ Build number 7 ครั้ง มือถือจะแจ้งว่า Developer mode On
2. เลือก Settings > Security and privacy. กด ปิด Auto Blocker
3. ที่เครื่องมือถือจะมีป๊อปอัพเตือนว่ามีการเสียบสาย USB เข้ากับเครื่อง MAC. ให้เลือกใช้งานตามจุดประสงค์
4. ให้ทำการติดตั้งโปรแกรม scrcpy โดยจะติดตั้งผ่าน homebrew.
ถ้ายังไม่เคยติดตั้งใช้งาน homebrew ให้ไปติดตั้ง homebrew ก่อน
ติดตั้ง Homebrew บน Mac (ถ้ายังไม่มี)
# /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
5. จากนั้นติดตั้ง ADB และ scrcpy ผ่าน Homebrew
brew install android-platform-tools # สำหรับ ADB
brew install scrcpy # ติดตั้ง scrcpy
6.เชื่อมต่อ S24 เข้ากับ Mac ผ่าน USB-C Cable
•ใช้สายแท้ หรือสายที่รองรับ Data Transfer
•หลังเสียบ → บนมือถือจะขึ้น “Allow USB Debugging?” → กด Allow
7.ตรวจสอบว่า Mac เจอ S24 หรือไม่
พิมพ์ใน Terminal:
adb devices
ถ้าเจออุปกรณ์มือถือจะแจ้งว่า
List of devices attached
xxxxxxxxxxxx device
8. รัน scrcpy
teee@NP Programs % scrcpy
scrcpy 3.1 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO: –> (usb) RFCxxxxxxxx device SM_S921B
/opt/homebrew/Cellar/scrcpy/3.1/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 106.3 MB/s (90640 bytes in 0.001s)
[server] INFO: Device: [samsung] samsung SM-XXXXX (Android 14)
INFO: Renderer: metal
INFO: Texture: 1080×2336
2025-03-17 15:31:22.355 scrcpy[37968:994087] +[IMKClient subclass]: chose IMKClient_Modern
2025-03-17 15:31:22.355 scrcpy[37968:994087] +[IMKInputSession subclass]: chose IMKInputSession_Modern
Install freeswitch 1.10.12 on debian12
root@san:~# apt-get update && sudo apt upgrade -y
root@san:~# apt-get install -y git build-essential autoconf automake libtool-bin g++ python3-dev uuid-dev zlib1g-dev libjpeg-dev libncurses5-dev libssl-dev libpcre3-dev libdb-dev libsndfile1-dev libedit-dev libldns-dev libcurl4-openssl-dev libpq-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libopus-dev libsndfile1-dev libtiff-dev libavformat-dev libswscale-dev liblua5.2-dev liblua5.3-dev libmpg123-dev libpq-dev libvpx-dev libopusfile-dev libshout3-dev libfreeimage-dev libyuv-dev libx264-dev cmake pkg-config libbroadvoice16-dev libsilk-dev libflite1-dev libilbc-dev libgsm1-dev libopenh264-dev unzip wget libswresample-dev
E: Package ‘libavresample-dev’ has no installation candidate
แพ็กเกจ libavresample-dev ถูกลบออกจาก Debian 12 (Bookworm) เนื่องจาก FFmpeg ได้เลิกใช้ libavresample แล้ว
apt install libswresample-dev
Download Freeswitch
https://files.freeswitch.org/freeswitch-releases/
root@san:~# cd /usr/src
root@san:/usr/src# wget https://files.freeswitch.org/freeswitch-releases/freeswitch-1.10.12.-release.tar.gz
root@san:/usr/src# tar xvf freeswitch-1.10.12.-release.tar.gz
root@san:/usr/src# cd freeswitch-1.10.12.-release
root@san:/usr/src/freeswitch-1.10.12.-release# ./rebootstrap.sh
เปืด Modules ที่ต้องการที่จะใช้งาน
root@san:/usr/src/freeswitch-1.10.12.-release# nano modules.conf
say/mod_say_th
databases/mod_mariadb
root@san:/usr/src/freeswitch-1.10.12.-release# ./configure –prefix=/usr/local/freeswitch –enable-core-pgsql-support
root@san:/usr/src/freeswitch-1.10.12.-release# make -j$(nproc)
make[4]: Entering directory ‘/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp’
CC mod_spandsp_la-mod_spandsp.lo
CC mod_spandsp_la-udptl.lo
CC mod_spandsp_la-mod_spandsp_fax.lo
CC mod_spandsp_la-mod_spandsp_dsp.lo
mod_spandsp_dsp.c: In function ‘get_v18_mode’:
mod_spandsp_dsp.c:159:17: error: ‘V18_MODE_5BIT_4545’ undeclared (first use in this function)
159 | int r = V18_MODE_5BIT_4545;
| ^~~~~~~~~~~~~~~~~~
mod_spandsp_dsp.c:159:17: note: each undeclared identifier is reported only once for each function it appears in
mod_spandsp_dsp.c:165:29: error: ‘V18_MODE_5BIT_50’ undeclared (first use in this function)
165 | r = V18_MODE_5BIT_50;
| ^~~~~~~~~~~~~~~~
mod_spandsp_dsp.c: In function ‘spandsp_tdd_send_session’:
mod_spandsp_dsp.c:216:21: error: too few arguments to function ‘v18_init’
216 | tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, NULL);
| ^~~~~~~~
In file included from /usr/local/include/spandsp.h:114,
from mod_spandsp.h:50,
from mod_spandsp_dsp.c:36:
/usr/local/include/spandsp/v18.h:138:29: note: declared here
138 | SPAN_DECLARE(v18_state_t *) v18_init(v18_state_t *s,
| ^~~~~~~~
mod_spandsp_dsp.c: In function ‘spandsp_tdd_encode_session’:
mod_spandsp_dsp.c:263:26: error: too few arguments to function ‘v18_init’
263 | pvt->tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, NULL);
| ^~~~~~~~
/usr/local/include/spandsp/v18.h:138:29: note: declared here
138 | SPAN_DECLARE(v18_state_t *) v18_init(v18_state_t *s,
| ^~~~~~~~
mod_spandsp_dsp.c: In function ‘spandsp_tdd_decode_session’:
mod_spandsp_dsp.c:341:26: error: too few arguments to function ‘v18_init’
341 | pvt->tdd_state = v18_init(NULL, FALSE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, pvt);
| ^~~~~~~~
/usr/local/include/spandsp/v18.h:138:29: note: declared here
138 | SPAN_DECLARE(v18_state_t *) v18_init(v18_state_t *s,
ที่เป็นแบบนี้เพราะ Module mod_spandsp มี BUG ที่แก้ไขแล้วแต่ไม่ได้แก้ไขที่ Code Release จะต้องทำการ patch ก่อน
https://github.com/zenthangplus/ansible-role-fsmrf/blob/9a73a47bfa19a485ddfc10f496bfc2041594f552/files/mod_spandsp_dsp.c.patch
root@san:/usr/src/freeswitch-1.10.12.-release# cd src/mod/applications/mod_spandsp/
root@san:/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp# wget https://raw.githubusercontent.com/zenthangplus/ansible-role-fsmrf/9a73a47bfa19a485ddfc10f496bfc2041594f552/files/mod_spandsp_dsp.c.patch
root@san:/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp# root@san:/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp# patch -p0 < mod_spandsp_dsp.c.patch ลอง make ดู root@san:/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp# make ถ้าไม่มี error ก็กลับไปลอง สั่ง make freeswitch ใหม่ root@san:/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp# cd /usr/src/freeswitch-1.10.12.-release root@san:/usr/src/freeswitch-1.10.12.-release# make clean ปรับแต่ง Banner root@san:/usr/src/freeswitch-1.10.12.-release# cd libs/esl/ root@san:/usr/src/freeswitch-1.10.12.-release/libs/esl/ee fs_cli.c static const char *banner =”YOUR BANNER email@mydomain.com”; root@san:/usr/src/freeswitch-1.10.12.-release/libs/esl# cd /usr/src/freeswitch-1.10.12.-release/src/include/ root@san:/usr/src/freeswitch-1.10.12.-release/src/include# mv cc.h cc.bak root@san:/usr/src/freeswitch-1.10.12.-release/src/include# nano cc.h const char *cc = “”; const char *cc_s = “”; root@san:/usr/src/freeswitch-1.10.12.-release/src/include# cd ../../ root@san:/usr/src/freeswitch-1.10.12.-release# ./configure –prefix=/usr/local/freeswitch –enable-core-pgsql-support root@san:/usr/src/freeswitch-1.10.12.-release# make install tab >q. กด Y
root@san:/usr/src/freeswitch-1.10.12.-release# make cd-sounds-install && make cd-moh-install && make uhd-sounds-install && make uhd-moh-install && make hd-sounds-install && make hd-moh-install && make sounds-install && make moh-install
root@san:/usr/src/freeswitch# make samples
root@san:/usr/local/freeswitch/conf/autoload_configs# cp event_socket.conf.xml event_socket.conf.orig
root@san:/usr/local/freeswitch/conf/autoload_configs# nano event_socket.conf.xml
<configuration name=”event_socket.conf” description=”Socket Client”>
<settings>
<param name=”listen-ip” value=”0.0.0.0″/>
<param name=”listen-port” value=”8021″/>
<param name=”password” value=”(YourPass)”/>
<!–<param name=”apply-inbound-acl” value=”loopback.auto”/>–>
<!–<param name=”stop-on-bind-error” value=”true”/>–>
</settings>
</configuration>
root@san:/etc# nano /etc/fs_cli.conf
[default]
; Put me in /etc/fs_cli.conf or ~/.fs_cli_conf
key_f1 => help
key_f2 => status
key_f3 => show channels
key_f4 => show calls
key_f5 => sofia status
key_f6 => reloadxml
key_f7 => /log console
key_f8 => /log debug
key_f9 => sofia status profile internal
key_f10 => fsctl pause
key_f11 => fsctl resume
key_f12 => version
[default]
profile => (Your Profile Name)
host => 127.0.0.1
port => 8021
password => (YourPass)
debug => 2
loglevel => debug
root@san:/etc# cd /usr/local/freeswitch/bin
root@san:/usr/local/freeswitch/bin# ln -s /usr/local/freeswitch/bin/freeswitch /bin/freeswitch
root@san:/usr/local/freeswitch/bin# ln -s /usr/local/freeswitch/bin/fs_cli /bin/fs_cli
root@san:/usr/local/freeswitch/bin# cd /usr/local/freeswitch/conf/
root@san:/usr/local/freeswitch/conf# cp vars.xml vars.orig
root@san:/usr/local/freeswitch/conf# nano vars.xml
<X-PRE-PROCESS cmd=”set” data=”ChangeDefaultPasswordToYourPassword”/>
Goto
FreeSWICH will default to $${local_ip_v4} unless changed. Changing this setting does
affect the sip authentication. Please review conf/directory/default.xml for more
information on this topic.
<!– Specific Macro Variables for Networking –>
<X-PRE-PROCESS cmd=”set” data=”domain=yourdomain.com”/>
<X-PRE-PROCESS cmd=”set” data=”local_ip_v4=(Your_IP_Address)”/>
<X-PRE-PROCESS cmd=”set” data=”local_mask_v4=(Your_Netmask)”/>
<X-PRE-PROCESS cmd=”set” data=”internet_public_ip_v4=(Your_Public_IP_Address)”/>
<X-PRE-PROCESS cmd=”set” data=”hostname=PBX”/>
<X-PRE-PROCESS cmd=”set” data=”session_name=PBX”/
<X-PRE-PROCESS cmd=”stun-set” data=”external_rtp_ip=(Your_Public_IP_Address)”/>
<X-PRE-PROCESS cmd=”stun-set” data=”external_sip_ip=(Your_Public_IP_Address)”/>
<X-PRE-PROCESS cmd=”set” data=”outbound_caller_name=(Your_Outbound_Number)”/>
<X-PRE-PROCESS cmd=”set” data=”outbound_caller_id=(Your_Outbound_Number)”/>
Save:Exit
ถ้ายังไม่มี freeswitch Start Script ให้ลอง Start ด้วย Command นี้ดู
root@san:# freeswitch -nonat -nc &
และลอง ใช้คำสั่ง netstat -lntup เพื่อดู freeswitch process
ลองใช้ fs_cli เพื่อเข้า console ดู
root@san:/usr/local/freeswitch/conf/autoload_configs# fs_cli
pbx.omtel.ltd teee@khun-teee.com
Type /help to see a list of commands
[This app Best viewed at 160×60 or more..]
+OK log level [7]
root@san:/usr/local/freeswitch/conf# nano /etc/systemd/system/freeswitch.service
[Unit]
Description=FreeSWITCH
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/usr/local/freeswitch
ExecStart=/usr/local/freeswitch/bin/freeswitch -u root -g root -nonat -nc
Restart=always
LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=60000
LimitSTACK=24000000
LimitRTPRIO=99
LimitRTTIME=7000000
IOSchedulingClass=realtime
IOSchedulingPriority=2
CPUQuota=80%
CPUSchedulingPolicy=rr
CPUSchedulingPriority=89
[Install]
WantedBy=multi-user.target
root@san:/usr/local/freeswitch/conf# sudo systemctl enable freeswitch
ข้อความ “Unable to negotiate with (router ip address) port 22: no matching key exchange method found”
ข้อความ “Unable to negotiate with 192.168.100.8 port 22: no matching key exchange method found” เกิดขึ้นเพราะ:
>Cisco IOS ใช้ Diffie-Hellman (DH) แบบเก่า เช่น diffie-hellman-group14-sha1 หรือ diffie-hellman-group-exchange-sha1
>SSH Client (เช่น OpenSSH, PuTTY) ไม่รองรับ DH แบบเก่าด้วยเหตุผลด้านความปลอดภัย
วิธีแก้ไข
1. ใช้ SSH Client ที่รองรับ DH แบบเก่า (ชั่วคราว)
หากใช้ OpenSSH บน Linux/macOS ให้ลองระบุ Key Exchange (KEX) ที่รองรับ:
#ssh -o KexAlgorithms=+diffie-hellman-group14-sha1 admin@192.168.x.x
หรือ
#ssh -o KexAlgorithms=+diffie-hellman-group-exchange-sha1 admin@192.168.x.x
ข้อเสีย: วิธีนี้ปลอดภัยน้อยลง ควรใช้แค่ชั่วคราว
2. เปิดใช้ Key Exchange ที่ใหม่กว่าใน Cisco Router
ถ้าเข้าถึง CLI ของ Cisco Router ได้ ให้เพิ่ม Key Exchange ที่รองรับ SHA2 หรือ ECDH
Router#configure terminal
Router#ip ssh dh min size 2048
Router#exit
Routetr#write memory # บันทึกค่า
จากนั้นลอง SSH ใหม่อีกครั้ง
3. อัปเกรด OpenSSH หรือ Cisco IOS (ถ้าเป็นไปได้)
>บน Linux/macOS อัปเดต OpenSSH เป็นเวอร์ชันใหม่ล่าสุด
>บน Cisco Router ถ้าใช้ IOS รุ่นเก่า ควรอัปเกรดเป็น IOS 15.7 หรือใหม่กว่า
แก้ปัญหา %Error opening tftp://255.255.255.255/(hostname)-confg (Timed out)
Error นี้มักเกิดขึ้นใน Cisco Router หรือ Switch เนื่องจากอุปกรณ์พยายามหาไฟล์ network-confg หรือ router-confg จาก TFTP Server เพื่อใช้เป็น Auto Configuration แต่ไม่มีไฟล์นั้นอยู่จริง
วิธีแก้ไข
1. ปิดการค้นหา Auto Configuration บน TFTP
หากไม่ต้องการให้ Router หรือ Switch ค้นหาไฟล์ network-confg สามารถปิดการทำงานนี้ได้โดยใช้คำสั่ง:
Router#configure terminal
Router#no service config
Router#exit
Router#write memory # บันทึกการตั้งค่า
คำสั่ง no service config ปิดฟังก์ชันการค้นหาไฟล์ Config ผ่าน TFTP Server
2. ตรวจสอบว่ามีการตั้งค่า BOOTP หรือ DHCP Option 66 ไว้หรือไม่
ถ้าอุปกรณ์ได้รับ IP จาก DHCP และ DHCP Server ส่ง Option 66 (TFTP Server) ไปด้วย อาจทำให้อุปกรณ์พยายามดาวน์โหลด Config จาก TFTP โดยอัตโนมัติ
ให้ตรวจสอบการตั้งค่า DHCP ด้วยคำสั่ง:
Router#show running-config | include dhcp
หากมีการตั้งค่าให้ลองปิดด้วยคำสั่ง:
Router#no ip dhcp bootp ignore
3. ตรวจสอบว่า Router หรือ Switch ได้รับ IP Address ถูกต้องหรือไม่
ใช้คำสั่ง:
Router#show ip interface brief
หากไม่มี IP Address ให้กำหนดใหม่ เช่น:
Router#interface GigabitEthernet0/0
Router#ip address 192.168.1.100 255.255.255.0
Router#no shutdown
Router#exit
4. หากต้องการใช้ TFTP จริง ๆ ให้ตรวจสอบการตั้งค่า TFTP Server
>ตรวจสอบว่า TFTP Server ทำงานอยู่
>ตรวจสอบว่า ไฟล์ network-confg มีอยู่จริง
>ตรวจสอบ Firewall ว่าเปิดพอร์ต UDP 69 หรือไม่
หากต้องการดาวน์โหลดไฟล์จาก TFTP Server ให้ใช้คำสั่ง:
Router#copy tftp://192.168.1.10/config.txt running-config
(เปลี่ยน 192.168.1.10 เป็น IP ของ TFTP Server)
วิธีแก้ปัญหา Cisco Router Write ลง Mem แล้ว Reload Config หาย
สรุปวิธีแก้ปัญหา
ให้ลองเช็ค config-register
#show version | include Configuration register
ถ้าเป็น 0x2142 ให้แก้เป็น 0x2102
ค่าปกติควรเป็น 0x2102
ถ้าเป็น 0x2142 แสดงว่า router ถูกตั้งค่าให้ข้าม startup-config
#configure terminal
#config-register 0x2102
#end
#write memory
#reload