SED Cheatsheet

bash

 

Some useful cheatsheet for sed:-

sed ‘2d’ file.txt Remove second line from file.txt
sed ‘/mickgenie/d’ file.txt Remove the line containing the word/string mickgenie from file.txt
sed ‘$d’ file.txt Remove last line from file.txt
sed ‘/^$/d’ file.txt Remove empty line from file.txt
sed ‘1,5d’ file.txt Remove line between 1 and 5 from file.txt

Howto: Clear Swap Cache

Recently I’ve wrote a script to calculate the swap usage and triggered the alert when Swap usage hit the certain level.

And I found out the actual memory usage is not using as it is where swap still caching the usage. To clear the swap cache and make the memory usage only, you may turn of swap by selecting the swap drive.

First of all, you need to identify the swap disk. Check the blkid for more information.

blkid

Look at the entry of swap. Assume swap is in sda5.

Turn the swap cache off,

swapoff /dev/sda5

Once it is done, turn on again,

swapon /dev/sda5

Centos: Check Raid device installed

To check if RAID device install to your server, simply run the following command from your  terminal.

# lspci | grep -i raid

With the above, you may simply get the raid device information.

[email protected] [~]# lspci|grep -i raid
04:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] (rev 05)

Howto: Install PDFlib-Lite and PDFlib on Centos server

To install PDFlib on Centos server, you may follow the guide below,

1. Download the PDFlib-Lite package,

cd /usr/local/src 
wget http://www.pdflib.com/binaries/PDFlib/705/PDFlib-Lite-7.0.5.tar

2. Extract and go to PDFlib-Lite folder,

tar -zxvf PDFlib-Lite-7-* 
cd PDFlib-Lite-7.0*

3. Configure PDFlib-Lite,

./configure --prefix=/usr/local

4. Create installation file and install it,

make
make install

5. Once PDFlib-Lite installed, download PDFlib with PECL,

pecl download pdflib

6. Extract and enter the folder,

tar xvzf pdflib-*.tgz 
cd pdflib-*

7. Create configuration file,

phpize

8. Configure, create configuration file and install PDFlib,

./configure
make
make install

9. A pdf.so will be created in your PHP extension folder, check it from PHP info,

php -i | grep extension_dir

10. If it is not exists, add the following line to the php.ini,

extension="pdf.so"

Centos: List SSH user last password changed date with cPanel

To secure your server with cPanel, you might want to consider to request your cPanel user to change your password quarterly.

To get this done, you may consider to use the command name chage.

[email protected] [~]# chage -l username
Last password change                                    : Jul 28, 2012
Password expires                                        : never
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 99999
Number of days of warning before password expires       : 7

To list all user Last password change date, you may do with the following command,

for i in `ls -l /var/cpanel/users | grep -vE '(\.|system)'| awk '{print $9}'`;do echo $i&&chage -l $i|grep Last;done;