Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Jan 082010
 

What does the run-parts mean in crontab?

Answer:

You might find the following lines in /etc/crontab

01 * * * * root run-parts /etc/cron.hourly

The actual meaning of run-parts is to run all the scripts in a given directory. So the above hourly cron means to execute all the scripts in the directory /etc/cron.hourly every hour.

See:

man run-parts

Jan 082010
 

Why sometimes kill does not work

Answer:

Sometimes you might noticed that kill statement does not work in some cases, e.g.

kill program

The reason is that the kill statement send a SIGTERM signal to the target process by default and tell the process to terminate itself. However, this signal can be catch up by the process and therefore can be ignored if the program's writer choose to ignore.

To kill a process at all cost, use

kill -9 program

SIGKILL will be send instead of SIGTERM, which cannot be caught or ignored.

Jan 082010
 

Prevent go way SSH session killing running job

Answer:

If you are executing a long running job over SSH session, when your SSH session is terminated for whatever reason, e.g. unstable network connection. Your long running job will die (it will receive a hangup/hup signal) when the SSH session was killed.

To overcome this, when executing long running job over SSH, use the following way

nohup program &

Jan 082010
 

How to combine insert & update in a single SQL statement

Answer:

It is quite common to check if a given record already exist in database (check by primary key), insert it if not found, or update it if found.

It can be easily done using the MySQL's ON DUPLICATE KEY UPDATE statement

INSERT INTO `foo` (id, num) values (1, 0) 
                             ON DUPLICATE KEY UPDATE num = num + 1;

Reference: http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html