Linux useful one liners
File operations
Search directory for large files (larger than 2GB) and show 10 largest
find Desktop/ -size +2G | xargs ls -l | sort +4nr -5 | head -n 10
+ larger than
- smaller than
c bytes
k Kilobytes
M Megabytes
G Gigabytes
Empty log file:
truncate -s 0 messages
truncate command makes the specified file of a needed size, if size (-s option) is zero, then the file will be empty.
Find how many times the specified Asterisk SIP extension was unreachable:
find Desktop/ -size +2G | xargs ls -l | sort +4nr -5 | head -n 10
+ larger than
- smaller than
c bytes
k Kilobytes
M Megabytes
G Gigabytes
Empty log file:
truncate -s 0 messages
truncate command makes the specified file of a needed size, if size (-s option) is zero, then the file will be empty.
Find how many times the specified Asterisk SIP extension was unreachable:
grep -Ei "9011.+unreachable" /var/log/asterisk/messages | awk '{split($1,month,"["); printf " %s %s %s %s\n", month[2], $2, $7, $10}' | sort -k 2 | uniq -c
1 Jan 10 '9011' UNREACHABLE!
10 Jan 11 '9011' UNREACHABLE!
2 Jan 12 '9011' UNREACHABLE!
1 Jan 16 '9011' UNREACHABLE!
18 Jan 18 '9011' UNREACHABLE!
1 Dec 28 '9011' UNREACHABLE!
4 Dec 29 '9011' UNREACHABLE!
2 Dec 30 '9011' UNREACHABLE!
6 Jan 6 '9011' UNREACHABLE!
1 Jan 9 '9011' UNREACHABLE!
Create asterisk dump file
From asterisk server shell:
tcpdump -w - -p -n -s 0 udp > /tmp/cli-capture.pcap
-w = output file
-p = don't start in promiscuous mode
-n = no name resolution
-s 0 = full frame, not only first bytes
udp = only capture udp packets
Then upload pcap file and analyze with Wireshark.
ethtool eth4
Settings for eth4:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
Supports Wake-on: pg
Wake-on: d
Current message level: 0x0000003f (63)
drv probe link timer ifdown ifup
Link detected: yes
Find needed NIC port
sometimes we can't find needed Ethernet NIC port of the rack server, we can use ethtool to make NIC blinking for specified amount of seconds:
ethtool -p eth4 15
1 Jan 10 '9011' UNREACHABLE!
10 Jan 11 '9011' UNREACHABLE!
2 Jan 12 '9011' UNREACHABLE!
1 Jan 16 '9011' UNREACHABLE!
18 Jan 18 '9011' UNREACHABLE!
1 Dec 28 '9011' UNREACHABLE!
4 Dec 29 '9011' UNREACHABLE!
2 Dec 30 '9011' UNREACHABLE!
6 Jan 6 '9011' UNREACHABLE!
1 Jan 9 '9011' UNREACHABLE!
Create asterisk dump file
From asterisk server shell:
tcpdump -w - -p -n -s 0 udp > /tmp/cli-capture.pcap
-w = output file
-p = don't start in promiscuous mode
-n = no name resolution
-s 0 = full frame, not only first bytes
udp = only capture udp packets
Then upload pcap file and analyze with Wireshark.
Network Related
View NIC parametersethtool eth4
Settings for eth4:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
Supports Wake-on: pg
Wake-on: d
Current message level: 0x0000003f (63)
drv probe link timer ifdown ifup
Link detected: yes
Find needed NIC port
sometimes we can't find needed Ethernet NIC port of the rack server, we can use ethtool to make NIC blinking for specified amount of seconds:
ethtool -p eth4 15
Getting Server Info
Vendor, Model, Serial:
dmidecode -t 1 | grep "Manuf\|Product\|Serial"
dmidecode -t 1 | grep "Manuf\|Product\|Serial"
Processor Sockets & Installed Processor:
dmidecode -t 4 | grep "Processor\|Socket\|Version"
RAM slots & Installed RAM:
dmidecode -t 17 | grep "Device\|Size\|DIMM_"
dmidecode -t 17 | grep "Device\|Size\|DIMM_"
HDD info:
smartctl -a /dev/your_device_here | grep "Vendor\|Product\|Capacity"
No comments:
Post a Comment