Too small to be put in separate post I will use this one "feature" post for putting all the little tricks I am using in my daily work. So when I remember something usefull or stumble on something new I't will go here...

  1. ldapsearch auto decode base64
  2. xenserver syslog level
  3. disable ipv6
  4. xen orchestra set NFS v4
  5. search string inside files
  6. search files recursively and copy
  7. redirect standard error (stderr)
  8. check on what ports server is listening

ldapsearch auto decode base64

When using ldapsearch and getting attribute values back coded in base64 It's nice and handy to have it auto decoded while your ldapsearch command is throwing output.

So just put into your .bashrc:

myldapsearch()
{
ldapsearch $* | perl -MMIME::Base64 -n -00 -e 's/\n +//g;s/(?<=:: )(\S+)/decode_base64($1)/eg;print'
}

And after that reload your .bashrc:


source .bashrc

Now whenever you use ldapsearch it will autodecode base64 values.


xenserver syslog level

There is still no way (at least not in XenCenter 7.3, later versions I haven't checked) to send custom level logs from xenserver into your central log server using GUI. Since default level is info you will be flooded with xapi info messages. Work around this is by manually editing rsyslog file on xenserver host /etc/rsyslog.d/xenserver.conf and at the end add:

.=warn;*.=crit;*.=err  @your.log.server

After that just restart rsyslog service with service rsyslog restart.


disable ipv6

To disable ipv6 put at the end in /etc/sysctl.conf:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1 

Then restart sysctl:


sysctl -p


xen orchestra set NFS v4

If needed you can set NFS to use v4 for your remotes (default is v3)


sudo nano /opt/xen-orchestra/@xen-orchestra/fs/dist/nfs.js

And change line where mount command is to use v4:

return (0, _execa.default)('mount', ['-t', 'nfs', '-o', 'vers=4'....

After just restart xo-server:


sudo service xo-server restart

search string inside files

If you need to search specific string inside files:


grep -rnw '/path/to/start/search' -e 'string'

search files recursively and copy

Sometimes you need to move specific files from inside multiple directories. Most this happen when TV show episode is in its own folder. Not sys admin problem but hey :)


find 'path/to/' -name '*.mkv*' -type f -exec mv {}  /path/to/season1/ \;

redirect standard error (stderr)

If you need to output command to a file writing:


ls /blabla > output.txt

This will still output of error messages in terminal. So to redirect those messages also use:


ls /blabla > output.txt 2> error.txt

The number 2 specifies the stream ID that the shell modifies. Stream ID
1 is standard output (the default), and 2 is standard error.
So if you like you can redirect both to the same file:


ls /blabla > log.txt 2>&1

check on what ports server is listening

To check what services are runing that is on what ports they are listening you can use netstat command from net-utils package:


sudo netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:10023         0.0.0.0:*               LISTEN      15662/postgrey --pi 
tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN      15882/master        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      462/sshd            
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      15882/master        
tcp        0      0 0.0.0.0:4190            0.0.0.0:*               LISTEN      6703/dovecot        
tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      6703/dovecot        
tcp6       0      0 :::587                  :::*                    LISTEN      15882/master        
tcp6       0      0 :::9100                 :::*                    LISTEN      415/node_exporter   
tcp6       0      0 :::22                   :::*                    LISTEN      462/sshd            
tcp6       0      0 :::25                   :::*                    LISTEN      15882/master        
tcp6       0      0 :::4190                 :::*                    LISTEN      6703/dovecot        
tcp6       0      0 :::993                  :::*                    LISTEN      6703/dovecot