Perpetual rsync

Automatically resume rsync over SSH after broken connection
Create a file in /bin/prsync

### COPY IN /bin/prsync - chmod 777 ###
# GitHub
# Extended by Gulshan Beejan - Persistent RSYNC# Make sure remote system has ssh key pairsif [[ -z $1 ]] ; then
echo "Persistent RSYNC Usage: prsync SOURCE DESTINATION"
if [[ -z $2 ]] ; then
echo "Persistent RSYNC Usage: prsync SOURCE DESTINATION"
fiwhile [ 1 ]
rsync -avz --partial $1 $2
if [ "$?" = "0" ] ; then
echo "prsync completed normally"
echo "==== prsync failure. ==== Backing off and retrying in 30 seconds..."
sleep 30

chmod +x /bin/prsync

then you can run it as:

prsync mysource_file.tar user@destination_ip:/path/to/file

Read More

Linux: Sudoers

What is it?

Sudoers is a list of users which may execute root commands. A sudoers file is made up of two types of entries, aliases and user specifications

How to set it up?

Do a visudo on command line, then add the user to the list as below.

If you want to enter the user’s password before executing the command:

myuser ALL=(ALL) ALL

And without a password:



Read More

My MySQL Server went down today!! Troubleshooting.


My MySQL Server went down today, which meant that my website was not working as well. When I checked, it clearly replied:

[root@sdb ~]# service mysqld status
mysqld is stopped

I automatically checked for the uptime of the server to see that it was a few hours ago. A chkconfig revealed that I forgot to add mysqld to autostart in run levels 2-5. Serious mistake, but since I reinstalled the server a few days ago, comprehensible.. i guess!

mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off

I then switched it to autorun and started the service via the following commands:


chkconfig mysqld on


service mysqld start

Solved! But not proper..

..The big question why did the server reboot?

I checked the logs at /var/log/messages to see the reason of the reboot.

less /var/log/messages

which revealed

Jun  1 03:08:06 sdb init: tty (/dev/tty1) main process (1972) killed by TERM signal
Jun  1 03:08:06 sdb init: serial (hvc0) main process (1974) killed by TERM signal
Jun  1 03:08:06 sdb init: tty (/dev/tty2) main process (1975) killed by TERM signal
Jun  1 03:08:06 sdb init: tty (/dev/tty3) main process (1977) killed by TERM signal
Jun  1 03:08:06 sdb init: tty (/dev/tty4) main process (1980) killed by TERM signal
Jun  1 03:08:06 sdb init: tty (/dev/tty5) main process (1982) killed by TERM signal
Jun  1 03:08:06 sdb init: tty (/dev/tty6) main process (1984) killed by TERM signal
Jun  1 03:08:12 sdb abrtd: Got signal 15, exiting
Jun  1 03:09:12 sdb init: Disconnected from system bus
Jun  1 03:09:12 sdb auditd[1824]: The audit daemon is exiting.
Jun  1 03:09:14 sdb kernel: Kernel logging (proc) stopped.
Jun  1 03:09:14 sdb rsyslogd: [origin software=”rsyslogd” swVersion=”4.6.2″ x-pid=”1839″ x-info=””] exiting on signal 15.
Jun  1 03:18:53 sdb kernel: imklog 4.6.2, log source = /proc/kmsg started.

What does this mean?

The system was shut down by an external person, Linode. I forgot they said that they would be having migration. Here’s the extract of the mail:

 * sdb – (7864940) System Shutdown – Completed Fri, 01 Jun 2012 03:08:07 GMT
* sdb – (7864941) Linode Initial Configuration – Completed Fri, 01 Jun 2012 03:09:28 GMT
* sdb – (7864942) Migrate Filesystem – swap from – Completed Fri, 01 Jun 2012 03:09:29 GMT
* sdb – (7864943) Migrate Filesystem – Data Disk from – Completed Fri, 01 Jun 2012 03:10:00 GMT
* sdb – (7864944) Migrate Filesystem – Backup Disk from – Completed Fri, 01 Jun 2012 03:12:36 GMT
* sdb – (7864945) Migrate Filesystem – CentOS 6.2 64bit Disk Image from – Completed Fri, 01 Jun 2012 03:15:02 GMT
* sdb – (7864946) Linode Migration Cleanup – Completed Fri, 01 Jun 2012 03:18:29 GMT
* sdb – (7864947) System Boot – SDB Config – Completed Fri, 01 Jun 2012 03:18:36 GMT

Happy as ever, I wrote a script to auto start a service if they have been found as not running, even if the server did not reboot. View it here.

Read More

Bash Script: Check service and auto start if needed

If you are running a service and for some reason the service gets broken, you will want it to automatically restart. For that reason, I have created a script as below. Feel free to amend the array autoservice as needed because in my case it is monitoring mysqld, cherokee and squid.

#Add values to the array autoservice seperated by spaces
autoservice=(mysqld cherokee squid)

#the code
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
for i in “${autoservice[@]}”
service $i status # > /dev/null
if [ $? -eq 0 ]; then
echo $i “Running..”
service $i restart

Created in /scripts/, you need to chmod 777 the file and add it to crontab to run every 5minutes via the following:


chmod 777 /scripts/


crontab -e

add this line to run it every 5 mintues

*/5     *       *       *       *       sh /scripts/

Read More

WordPress Mail – VPS CentOS 6.2

I recently re-installed centos on the VPS and almost forgot that I needed sendmail on the server to send out my daily backups. The backup is run from a plugin called WordPress Database Backup.

Installation is fairly easy with the following steps:

Check if sendmail has been installed

 [root@sdb ~]# rpm -qa sendmail
[root@sdb ~]#

if it is, update to the latest version

yum update sendmail

Else, let’s install it.

yum install sendmail


[root@sdb ~]# yum install sendmail
Loaded plugins: fastestmirror, priorities, security
Loading mirror speeds from cached hostfile
epel/metalink                                            |  16 kB     00:00
* base:
* epel:
* extras:
* ius:
* rpmforge:
* updates:
base                                                     | 3.7 kB     00:00
epel                                                     | 4.0 kB     00:00
epel/primary_db                                          | 4.4 MB     00:00
extras                                                   | 3.5 kB     00:00
ius                                                      | 2.2 kB     00:00
ius/primary_db                                           |  71 kB     00:00
rpmforge                                                 | 1.9 kB     00:00
updates                                                  | 3.5 kB     00:00
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package sendmail.x86_64 0:8.14.4-8.el6 will be installed
–> Processing Dependency: procmail for package: sendmail-8.14.4-8.el6.x86_64
–> Processing Dependency: for package: sendmail-8.14.4-                                                                                     8.el6.x86_64
–> Running transaction check
—> Package hesiod.x86_64 0:3.1.0-19.el6 will be installed
—> Package procmail.x86_64 0:3.22-25.1.el6 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

Package           Arch            Version                  Repository     Size
sendmail          x86_64          8.14.4-8.el6             base          717 k
Installing for dependencies:
hesiod            x86_64          3.1.0-19.el6             base           20 k
procmail          x86_64          3.22-25.1.el6            base          163 k

Transaction Summary
Install       3 Package(s)

Total download size: 900 k
Installed size: 1.9 M
Is this ok [y/N]:

Y to continue, the installation will complete.

Start Sendmail

service sendmail start

Accept incoming mail

You will need to modify the file in /etc/mail/local-host-names through vi

vi /etc/mail/local-host-names

Add your server hostnames to accept mail from.

In my scenario, it would be

Restart Sendmail Service

service sendmail restart

Testing was done, and it worked. =)

Read More