Ubuntu 9 server cron jobs (cron.daily, cron.weekly etc)

I have some backup scripts that live in my home directory and are symlinked into the /etc/cron.daily and cron.weekly etc dirs. Apparently run-parts will not run scripts that have a ‘.’ in the filename, so the symlink to the .sh files has to be named minus the file extension.

Also, testing the scripts with ‘sudo runparts /etc/crond.daily’ gave errors like this:

<code>run-parts: failed to exec /etc/cron.daily/update_apache_logs: Exec format error</code>

To fix this, I added this to the top of each of the scripts:

<code>#!/bin/sh</code>

Making changes to /etc/profile

If you make changes to /etc/profile and want them to take effect immediately without rebooting, run the script using . ./profile (assuming the file has execute flag set, if not chmod +x profile to set it).

Blacklisting incoming sites using iptables

Use this command to add an ip address to be blocked by iptables:

<code>
iptables -I INPUT -s x.x.x.x -j DROP
iptables -I INPUT -s x.x.x.x -j LOG
</code>

This example inserts a rule at the top of the table to block all incoming requests from ip x.x.x.x, and then inserts a second rule at the top to first log any connection attempts from this address (before they are blocked).

To see what rules are currently configured, use: iptables -L

For more info, see this entry in the O’Reily Linux Hacks book.