Little Helpers – Linux

linux-logo

Rsyslog: Receive Logs and Store to Flat Files

Sample config for Rsyslog:
Receives logs on TCP and UDP port 514 and stores them locally under /var/log/hosts/$hostname$

/etc/rsyslog.conf


# Use traditional timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# Setting default group of new logfiles
$FileGroup adm

### Modules
$ModLoad imklog
$ModLoad imuxsock
$ModLoad imtcp
$ModLoad imudp

### Templates
# RemoteHost
$template RemoteHost,"/var/log/hosts/%fromhost%"

### Rulesets
# Local Logging
$RuleSet local
*.info;mail.none;authpriv.none;cron.none                /var/log/messages
authpriv.*                                              /var/log/secure
mail.*                                                  -/var/log/maillog
cron.*                                                  /var/log/cron
*.emerg                                                 *
uucp,news.crit                                          /var/log/spooler
local7.*                                                /var/log/boot.log

# use the local RuleSet as default if not specified otherwise
$DefaultRuleset local

# Remote Logging
$RuleSet remote
*.* ?RemoteHost

### Listeners
# TCP
$InputTCPServerBindRuleset remote
$InputTCPServerRun 514

# UDP
$InputUDPServerBindRuleset remote
$UDPServerRun 514

Extend a XFS volume/partition

I don’t cover the physical extension of the volume here, I assume the volume has already been extended.


[root@bigmamma ~]# umount /xyz
[root@bigmamma ~]# blockdev --rereadpt /dev/sda
[root@bigmamma ~]# parted /dev/sda

GNU Parted 1.7.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print

Disk /dev/sda: 100GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  80.5GB  80.5GB  primary  xfs

(parted) rm  1
(parted) mkpart primary xfs 32.3kb -1
(parted) print

Disk /dev/sda: 100GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  100GB   100GB   primary  xfs

(parted) quit

[root@bigmamma ~]# mount /xyz
[root@bigmamma ~]# xfs_growfs /xyz

Debian: Keep NICs listen to Wake on LAN

Unfortunately, setting the wol parameter via ethtool is not persistent. It has to be set after every reboot (or NIC up/down). Before you mess around with some init scripts, just add the two lines below to your NIC config:

/etc/network/interfaces


iface eth0 inet ...
        ...
        post-up /sbin/ethtool -s $IFACE wol g
        post-down /sbin/ethtool -s $IFACE wol g
        ...

ethtool manpage: http://linux.die.net/man/8/ethtool

Changing the ownership of a users files to another user


find /folder -user oldowner -exec chown newowner {} \;

Infinitely Looping a command

Might be handy to monitor something happening (i.e. change of disk usage)

for (( ; ; )) do command1; sleep xx; done

Using screen

Starting screen: screen
Resume last session: screen -R
Resume session specified: screen -r [pid]

While screen is running
Detach: [Ctlr][a] + [d]
Create new session and switch to it: [Ctlr][a] + [c]
Send a [Crtl][q] to the current window: [Ctrl][a] + [Ctrl][q]
Show a list of existing windows: [Ctrl][a] + [Ctrl][w]
Show a listing of attached windows: [Ctlr][a] + [*]

Creating a LVM Volume Group on a huge disk (bigger than MBR can handle [2.2TB])


[root@bigmamma ~]# parted /dev/sdx

GNU Parted 1.8.1
Using /dev/sdx
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print

Model: 1337 Kickass diskcontroller (scsi)
Disk /dev/sdx: 20TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

(parted) mklabel gpt

(parted) mkpart primary 0 20TB
(parted) print

Model: 1337 Kickass diskcontroller (scsi)
Disk /dev/sdx: 20TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
1      17.4kB  20TB  20TB               primary

(parted) quit
[root@bigmamma ~]# pvcreate /dev/sdx1
[root@bigmamma ~]# vgcreate /dev/sdx1

Mounting a ISO image with the loop kernel module


mkdir /mnt/iso
modprobe loop
mount /xxx/yyy.iso /mnt/iso -t iso9660 -o loop

Debian: Reading System Sensors (Temp., Voltages etc.)


apt-get install lm-sensors
sensors-detect
sensors

Debian: Reading HDD temperatures


apt-get install hddtemp
hddtemp /dev/sdX

Exim: Delete multiple mails from queue


exim -bpru | tr '\n' + | sed -e "s/++/=/g" | tr -d + | tr = '\n' | grep "foo@bar.com" | awk {'print $3'} | xargs exim -Mrm

MySQL: Checking the charset of a DB


mysql> use xyz;
mysql> show variables like "character_set_database";
+------------------------+--------+
| Variable_name          | Value  |
+------------------------+--------+
| character_set_database | latin1 |
+------------------------+--------+
1 row in set (0.01 sec)

mysql> show variables like "collation_database";
+--------------------+-------------------+
| Variable_name      | Value             |
+--------------------+-------------------+
| collation_database | latin1_swedish_ci |
+--------------------+-------------------+
1 row in set (0.00 sec)

Leave a Reply

Your email address will not be published. Required fields are marked *

*