ThickBox is a very cool JavaScript to give your home page a famous Web 2.0 look and feel when displaying images. I love this tool, it’s so easy to use ’cause basically you must only declare the following html snippet (and of course include the CSS and JavaScript files before):
<a href="image.jpg" title="title" class="thickbox">
<img src="image_thumbnail.jpg" alt="Image"/>
</a>
Unfortunately ThickBox support only static pictures out of the box. More precisely only image sources (img src) including the file extension “.jpg” etc. will be displayed correctly. Dynamically generated images e.g. that ends with “.php” will be displayed as follows:
<a href="image.php?id=1001" title="title" class="thickbox">
<img src="image.php?id=1001&thumbnail=1" alt="Image"/>
</a>

So how can you teach ThickBox to support this type of pictures? This is very important if you create images on demand using PHP or if the image is on a location which is not within the document root (and must be loaded from disk e.g. for permission reasons). Just add the .php extension to the thickbox.js JavaScript file (line 65 and 68) as follows. Afterwards it will look perfectly.
65
66
67
68
69
70
| var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$|\.php$/;
var urlType = baseURL.toLowerCase().match(urlString);
if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' ||
urlType == '.gif' || urlType == '.bmp' || urlType == '.php'){
//code to show images |

Here comes a Perl script that uses a real SMTP connection for sending mail. That’s very useful e.g. if you want to send the result of a backup process via mail to the administrator. The only thing you have to do is complete the 5 variables server, sender, recipient, subject and message.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| #!/usr/bin/perl
use Net::SMTP;
$server = "localhost";
$sender = "sender <sender\@host.tld>";
$recipient = "recipient\@host.tld";
$subject = "Test";
$message = "Hello World!";
$smtp = Net::SMTP->new($server);
$smtp->mail($sender);
$smtp->to($recipient);
$smtp->data();
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("From: $sender\n");
$smtp->datasend("To: $recipient\n");
$smtp->datasend("\n");
$smtp->datasend("$message");
$smtp->dataend();
$smtp->quit; |
And here are two further hints:
- Use the tag symbols inside the sender variable to define an additional real name for the mail address
- Use the
<STDIN> keyword to read text from the standard input to fill the subject or message variable
Here comes an example of a simple backup shell script that “tar“s the specified directory to an archive and uploads it on a FTP server using curl. Afterwards the local backup file will be removed. The only thing you have to do is define at least BACKUP_DATA, BACKUP_SERVER, BACKUP_USERNAME and BACKUP_PASSWORD.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| #!/bin/sh
# Name of the backup file
BACKUP_NAME="backup.tar.gz"
# Directory of the backup file
BACKUP_PATH="/tmp/"
# Directory + Name
BACKUP=${BACKUP_PATH}${BACKUP_NAME}
# Backup data
BACKUP_DATA="/home/username"
# Backup server
BACKUP_SERVER="ftp.backup.tld"
# Username and password
BACKUP_USERNAME="username"
BACKUP_PASSWORD="password"
# Execute backup
tar --exclude=${BACKUP} -czf ${BACKUP} ${BACKUP_DATA}
if [ "$?" -ne "0" ]; then
echo "tar: Backup failed!"
exit 1
fi
curl --upload-file ${BACKUP} ftp://${BACKUP_SERVER}\
--user ${BACKUP_USERNAME}:${BACKUP_PASSWORD}
if [ "$?" -ne "0" ]; then
echo "curl: Backup failed!"
exit 1
fi
rm ${BACKUP}
echo "Backup (" $(date) ") successful!" |