Occasionally I find myself needing to mount a remote file system on a local *BSD or Linux machine. On one such occasion recently I had mounted an NFS file system from a Network Attached Storage (NAS) server to a local machine running FreeBSD, for the purpose of backing up some of the files to yet another machine offsite using the rsync utility. I had created a little script to run rsync periodically through cron. This script worked well until I noticed a few days later that the backups on the remote machine no longer existed. After some investigation I quickly determined that NAS file system was no longer mounted on the FreeBSD machine (I can neither confirm or deny that I may have configured something incorrectly). The rsync script, upon noticing that files no longer existed in the source, deleted said files at the target. It was at that point that I decided to include a small test in the rsync script to check on the existence of the mounted file system; then, if it still existed, the script would proceed with the rsync command, else it would write an error message to a log. Here is the code snippet I used in the script, which you can easily adapt for other situations:
1
2
3
4
5
6
df|grep-q/mnt/files
if[$?=0];then
$RSYNC$OPTIONS$SOURCE$TARGET>>$LOG2>&1
else
echo$ERR_MSG>>$LOG
fi
The df command simply displays statistics about the amount of free disk space on the specified file system. If a file system argument is not specified, statistics for all mounted file systems are displayed. The output of the df command is then piped through the venerable grep utility using its -q option, which instructs grep not to write anything to standard output, but rather exit immediately with a zero status if a match is found. Finally, the file system we’re interested in matching to, parsed from the output of the df command, is provided to grep. If the output of this df command is zero, the script runs a command (in this case my rsync command), else if it exits with anything other than zero, the script runs another command instead (in this case an error message).
I’ve added a Your IP tab at the top of the site that will bring you to a page that displays your current IP address as well as some other http connection-related information. A geeky little task I’ve been meaning to do for awhile now. Here’s the code I hacked together for it. As always, please report any problems you encounter with it, and any suggestions you may have for ways to improve the code and/or experience.
PHP
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
This post describes how to fix duplicate meta and title tag content when spanning multiple home pages in WordPress. This isn’t a topic I normally cover here at www.iceflatline.com, but after searching for a solution to this problem for this site and continually encountering advice such as just add a plugin, I decided to post how I fixed this problem without encumbering my site with yet another WordPress plugin or other solutions.
The Problem
Like each post here at iceflatline.com, my index or main “home” page contains its own unique description and keywordsmeta tags and title tag content. WordPress allows me to determine the number of posts displayed on my home page (I typically choose five). Once this limit is reached, my WordPress theme automatically generates an “Older Entries” link at the bottom of the page, allowing the reader to navigate to a another page containing the previous five posts, and so on. While this is a helpful navigation feature for the reader, to a search engine like Google it’s another URL that contains the same meta and title tag content as that of the main home page. For example, I use the following content for my home page description and keywordsmeta tags:
XHTML
1
2
3
<meta name="description"content="Here at www.iceflatline.com you will find how-tos, tutorials, tips, guides, news, reviews and commentary for users of Linux, Unix and Windows">
Left unchanged, however, each Older Entries link will also contain the same description and keywords content. Consequently, tools like Google’s Webmaster Tools will complain that it has detected duplicate meta descriptions. This issue likely won’t prevent your site from appearing in search results, but paying attention to it can provide Google and other search engines with more information and help drive traffic to your site.
The Solution
To fix the problem of duplicate meta and title content I added a bit of PHP code to my theme’s header.php file. When a reader of iceflatline.com uses the Older Entries link to view a page containing its previous five posts, this code will automatically prepend or append a page number to the contents of these tags so that the metadata in each of these pages appears unique to the search engine. The page numbering starts with 2 and increments each time the reader navigates to a previous page.
Duplicate Meta Tag Content
To eliminate duplicate description and keywordsmeta tag content, I added the following PHP code to my theme’s header.php file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?phpif(is_home()){
echo'<meta name="description" content="';
if($paged<2){
}else{
echo'Page '.($paged).' | ';
}
echo'Here at www.iceflatline.com you will find how-tos, tutorials, tips, guides, news, reviews and commentary for users of Linux, Unix and Windows"/>';
Now when someone clicks on Older Entries the description and keywordsmeta tag content will be prepended with a page number so that it looks like this:
XHTML
1
2
3
<meta name="description"content="Page 2 | Here at www.iceflatline.com you will find how-tos, tutorials, tips, guides, news, reviews and commentary for users of Linux, Unix and Windows"/>
If desired, the following variations of the code above will append the page numbers instead:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?phpif(is_home()){
echo'<meta name="description" content="Here at www.iceflatline.com you will find how-tos, tutorials, tips, guides, news, reviews and commentary for users of Linux, Unix and Windows.';
To eliminate duplicate title tag content, I appended the following PHP code to the tag’s existing contents in my theme’s header.php file:
1
2
3
4
5
if($paged<2){
}else{
echo(' | '.'page ');
echo($paged);
}
Combined with the original code, the revised PHP code within the title tags now looks like this:
1
2
3
4
5
6
7
8
9
10
11
<title><?phpwp_title(' ');
if(wp_title(' ',false)){
echo' | ';
}
echobloginfo('name');
if($paged<2){
}else{
echo(' | '.'Page ');
echo($paged);
}
?></title>
Now when someone clicks on Older Entries the title description will be appended with a page number so that it looks like this:
XHTML
1
<title>iceflatline | Page 2</title>
Conclusion
There ya have it. A bit PHP code and I fixed these nagging problems, and saved myself the hassle of having to update and manage yet another WordPress plugin or use some other solution that didn’t fully meet my needs.