If you need to get value of last column in awk you can use built-in variable NF which means the number of fields in record. awk ‘$(NF) !~ /-/ { print $0 }’ access_log Or next, if you need next to the last field. And so on. awk ‘$(NF-1) != /-/ { print $0 }’…
All posts by Oleksii Tykhonov
DRBD split-brain solution in primary/primary setup
Recently one of our customers DRBD cluster has detected split-brain: node2 kernel: block drbd1: Split-Brain detected, dropping connection! node2 kernel: block drbd1: helper command: /sbin/drbdadm split-brain minor-1 node2 kernel: block drbd1: helper command: /sbin/drbdadm split-brain minor-1 exit code 0 (0x0) This is primary/primary cluster. And to fix this issue we had to perform manual procedures…
RPM: last installed packages
1. To get list of last installed RPM packages you can simply use next command: rpm -qa –last | less 2. To get list of packages installed sorted by size use: rpm -qa –queryformat=”%{size} %{name}-%{version}-%{release}n” | sort -rn | less Didn’t find the answer to your question? Ask it our administrators to reply we will…
Python: how to get list of listen sockets in Linux
Here is an example of Python code to get listen socket from Python: def listen_sockets(): listens = [] lines = open(“/proc/net/tcp”).readlines() for l in lines: ls = l.split() if ls[3] == ‘0A’: lp = ls[1].split(‘:’) ip = str(lp[0]) pair = “%s.%s.%s.%s:%s” %( int(ip[6:8], 16), int(ip[4:6], 16), int(ip[2:4], 16), int(ip[0:2], 16), int(lp[1], 16)) listens.append(str(pair)) return listenslistens…
Using ncat to transfer files without SSH
Sometimes you want to transfer some files between two servers but with no SSH installed. There are a lot of ways to do it but the simplest one is to use ncat from nmap package. On receiver you should run: [root@server1 ~]# ncat -v -lp 2223 < ~/fileNcat: Version 5.21 (http://nmap.org/ncat) Ncat: Listening on 0.0.0.0:2223…
Getting idle processes PID from Perl
There is a nice lib for Perl for working with processes in Linux. And it could be used to get PIDs of processes that have been working more than some amount of time. #!/usr/bin/perl -w use strict; use Proc::ProcessTable; my $period = time-(2*60*60); # in this case it’s two hours my $t = new Proc::ProcessTable;…
How to block huge amount of IP addresses with use of ipset in Fedora 14
Sometime you need to block really big numbers of IP addresses. It could be for different reasons. For example, in case of password bruteforce, DDoS attack. Of course, you can block them just in iptables. But there can be a problem. If set of IP addresses contain thousands of items iptables performance decreases (actually, performance…
How to backup and restore your LDAP database
LDAP is Lightweight Directory Access Protocol. It is a way to communicate with directory services. And for many years it has proved its reliability to organize and keep various type of information, for instance, user accounts. It’s useful if you want to provide one credentials for accessing to different resources – servers, web pages, etc.…
Using SNMP extend feature in Nagios
In Supportex we monitor a lot of web services and devices. One of the most convenient ways to monitor various parameters is SNMP extend feature. Let’s consider how it works. Assume you already have SNMP daemon installed. Firstly you need to add configuration line in you SNMP daemon config and restart daemon: extend raid-md0 /usr/local/bin/check_md_raid.pl…
Three ways to make MySQL database dump
Everybody knows – backups are very important. Today a lot of web projects use MySQL to keep data. So you need to know how to set up reliable but simple backup of all your databases. And even if you are only developing you might probably need some tools to make quick dumps and to restore…