Using vim as a diff and merge tool

with Andrej’s article I found some nice tips & tricks and the Vim manual for diff tasks. Some useful commands,

* “vim -o one.txt two.txt three.txt” (for horizontal split), “vim -O one.txt two.txt three.txt ” (for vertical split)
* go to the next diff point ” ]c “; go to previous diff point “ [c “
* merge to original “do“, merge from original “dp“.
Where text highlighted red will display text which doesn’t match from the files being compared.

Script to daily email APF status

You are running APF on your server, but sometimes you think “is APF running fine?”
This script sends you an email with APF satus.

Log in to your server as root

Create the script:
# nano

Put this on the file:

tail -200 /var/log/apf_log | mail -s “APF Status”

Save and Exit

Make it executable:
# chmod 755

Move it to “/etc/cron.daily” folder:
# mv /etc/cron.daily

You will receive now a daily email with APF status.

Run TOP in batch mode

top can be run non-interactively, in batch mode. Time delay and the number of iterations can be configured, giving you the ability to dictate the data collection as you see fit.

Here’s an example:
top -b -d 10 -n 3 >> top-file

We have top running in batch mode (-b). It’s going to refresh every 10 seconds, as specified by the delay (-d) flag, for a total count of 3 iterations (-n). The output will be sent to a file.

Crontab Basics

Change to the user you want to, then open the crontab editor:
# crontab -e

you can use this variables:

a = the minute after the hour that you want it done
b = the hour you want it done
c = Day of the Month
d = Month of the Year
e = Day of the week
f = ‘command you want to execute’
* = ALL

10 0 * * * /usr/local/aplication
It will run the application every day at 12:10 AM.
* * * – means all day of the month, all month of the year, all day of the week

Other crontab commands:
crontab -e opens the editor
crontab -l lists the contents of the crontab
crontab -r removes the crontab

Can’t connect to local MySQL server through socket

I you are reading this, probably you are getting the next error:

/usr/local/bin/mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)’
Check that mysqld is running and that the socket: ‘/tmp/mysql.sock’ exists

To fix it, and if you are running cPanel just try to run the next commands:

# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

# /scripts/mysqlup –force

Fix Not Found Error on rvsitebuilder – The server was not able to find the document

If you get the next problem on rvsitebuilder running on a cpanel server:

Not Found

The server was not able to find the document
(./3rdparty/rvsitebuilder/index.php/sitebuilder/sitebuilderhome) you
Please check the url and try again. You might also want to report this
error to your webhost.

It should fix the problem to you:

Log in as root on your cpanel server and run these commands:

# rm -f /var/cpanel/rvglobalsoft/rvsitebuilder/var/INSTALL_COMPLETE.php
# rm -f /var/cpanel/rvglobalsoft/rvsitebuilder/rvsitebuilderversion.txt
# perl /usr/local/cpanel/whostmgr/docroot/cgi/rvsitebuilderinstaller/autoinstaller.cgi

Open your WHM on a web browser, https://serverip:2087

And go to root WHM -> Plugins -> RVSiteBuilder

It will automatically rebuild the database for you and should fix the problem.

Single cPanel Account Backup Restore using SSH

You can backup a single cPanel account trough ssh using pkgacct cPanel script located at /scripts folder on your server. This tip is helpful for WebHosting companies that uses cPanel as Hosting control Panel

– Login to your cPanel server as root.

To backup a sigle account use the next commands:
# cd /scripts
# ./pkgacct username
These commands will crate a file named “cpmove-username.tar.gz” on /home directory. And this is the file you need to restore on this server latter or on other server.

How to restore cPanel sigle account on other server

You just need to upload “cpmove-username.tar.gz” to the server you want to restore it or you can do it in the first server if you want. To upload you can use ftp, rsync or scp.

Restoring cpmove-username.tar.gz:

– “cpmove-username.tar.gz” should be on /home directory

Run the next command:
# /scripts/restorepkg username

It will restore homedir, dbs, mail, all the old cPanel account.

Recovering the root password from the boot loader (GRUB)

When GRUB loads up, select the Red Hat Linux entry on the GRUB menu and then press “e” to edit the boot configuration.

Locate a line like this:

kernel /boot/ root=LABEL=/hdc

– type the number ‘1’ at the end.

Doing so boots the computer into run level 1- single user mode you will automatically be logged in as root.

Type ‘passwd’ at the prompt, now you can enter a new password here.