Check whether the server is virtual or physical

1. Install the package : facter
In centOS : yum install facter
In ubuntu : apt-get install facter
2. Run the command :

facter virtual

3. Check the output.

for example :

[root@test1 ~]# facter virtual
vmware
root@test2:~# facter virtual
physical

Thanks ๐Ÿ™‚

Extra Password protection for wordpress

In cPanel, there is an option to lock the folders with a password. In normal case, it wont work with WordPress. In my case, below steps worked fine.

1. Add password authentication for the folder with wordpress files from cPanel
2. Create the user and password

3. Add following lines to the .htaccess file in the wordpress root directory

ErrorDocument 401 ./error.html
ErrorDocument 403 ./error.html

 

4. Final .htaccess will look as below:

#next two lines allow password protected directories with 404 errors
ErrorDocument 401 ./error.html
ErrorDocument 403 ./error.html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dev/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dev/index.php [L]
</IfModule>

# END WordPress
#-- Following lines are added for password authentication in the site
AuthUserFile "/home/user_name/.htpasswds/public_html/sub_domain/passwd"
AuthName "dev"
AuthType Basic
require valid-user

 

 

Enjoy ๐Ÿ™‚

Bash script to take Mysqldump hourly and daily

Create a script as below and make it executable:

#!/bin/bash
Now_hourly=$(date +%d-%b-%H_%M)
Now_daily=$(date +%d-%b-daily)
if [ "$1" == "hourly" ]; then
/usr/bin/mysqldump --all-databases | gzip -c | cat > /Backup_location/mysql_dump_all$Now_hourly.sql.gz
elif [ "$1" == "daily" ]; then
/usr/bin/mysqldump --all-databases | gzip -c | cat > /Backup_location/mysql_dump_all$Now_daily.sql.gz
else
echo "Error. Enter hourly or daily";
fi

Now add the script in crontab for the hours it should run.

15,30 1,3 * * * script_name hourly
10,20 2,4 * * *ย script_name daily

Hourly backup will run at 01:15,01:30,03:15 and 03:30

Daily backup will run at 02:10,02:20,04:10 and 04:20 (since name would be same, it will replace each daily backup before)