Archive for the 'Cron' Category
Gnome background changer
Gnome 2.3 on Ubuntu 10.04 LTS (Lucid Lynx) doesn’t appear to have an automatic wallpaper changer built in. While it appears there are many ways to accomplish this, I decided to write my own little script to get some time in with bash… alternative ways I have found include using “Wallpaper-tray” (which doesn’t appear to be in 10.04), Desktop Drapes, or a variation of the script below using things like “gconftool-2“.
To use this script, do the following:
- Right-click on the desktop and choose “Change Desktop Background“
- Look through the backgrounds, and make sure the ones listed are the ones you want to have the script randomly select
- Open up a text file using “gedit“, and add the contents of the script:
#!/bin/bash
installedDir=~/Pictures/backgrounds/randomi=0
while read line; do
data=`echo "${line}" | grep -i filename`
if [ "$data" != "" ]; then
filenameCutLength=$((${#data}-11))
filename=$(echo $data | cut -b11-$filenameCutLength)
if [ "$filename" != "(none)" ] || [ "$filename" != \
"random.img" ]; then
extension=$(echo ${filename,,} | \
cut -b$(expr ${#filename} - 2)-${#filename})
if [ "$extension" == "jpg" ] || [ "$extension" \
== "png" ] || [ "$extension" == "svg" ]; then
fileArray[$i]=$(echo $filename)
i=$(expr $i + 1)
fi
fi
fi
done << EOF
$(grep deleted=\"false -A7 ~/.gnome2/backgrounds.xml)
EOFfileArrayLength=`echo $[ ( $RANDOM % ${#fileArray[@]} ) ]`
cp "${fileArray[$fileArrayLength]}" \
"$installedDir/random.img" - Save the file as “gRandomBackground.sh” in a directory (this example uses: “/home/$USER/Pictures/backgrounds/random”, if you install it elsewhere, be sure to change the $installedDir variable in the script)
- Open “Terminal” and enter the command:
crontab -e
If you haven’t used crontab before, stick with the default, “nano“
- Paste the following as one line into the editor:
0 */3 * * * bash ~/Pictures/backgrounds/random/gRandomBackground.sh
This will change the background every three hours, on the hour. “Ctrl+O, and then Ctrl+W” should get the crontab saved and also get you exited out of nano. For more information on how to use cron, see Google.
- Open up the “Appearance Preferences” dialog again, by right-clicking on the desktop and selecting “Change Desktop Background“
- Click the “Add…” button and browse to the directory that gRandomBackground.sh is installed to
- Select the “random.img” background, click the “Open” button, and then the “Close” button
Your background should change every three hours.
Posted by Karl Herrick on June 16th, 2010 in Linux, Cron, Bash | Comments Off
Goldfish and forged spam
Recently I had the goldfish autoresponder (vacation responses / email auto reply) setup for a user for about one week. Checking their inbox about half way through this time period revealed it having over 47,000 unread messages. What was happening is that spammers were sending email with forged headers. Have you ever received a spam message that apparently has been sent from yourself?
I suppose it can be accomplished via a variety of ways, however I was able to reproduce this particular issue via generating one of these tasty spam mails via the following (all internally of course… I am not a spammer):
and then issuing these commands:
mail from:<emailuser@example.com>
rcpt to:<emailuser@example.com>
data
From: <emailuser@example.com>
To: <emailuser@example.com>
Subject: testing a loop
Message text
.
quit
Notice the mail is being sent to the user… and from the user…
- The server would receive the email addressed to emailuser@example.com
- goldfish would parse the message and notice it needed to respond to… emailuser@example.com
- The mail was delivered
- Rinse, wash, repeat
The source of the message looked something like this:
Return-Path: <emailuser@example.com>
Delivered-To: emailuser@example.com
Received: from localhost (localhost [127.0.0.1]) by server.example.com (Postfix) with ESMTP id 923E9185F7 for <emailuser@example.com>; Thu, 4 Sep 2008 15:37:42 -0400 (EDT)
X-Virus-Scanned: Debian amavisd-new at server.example.com
Received: from server.example.com ([127.0.0.1]) by localhost (server.example.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q3tScOaitRoS for <emailuser@example.com>; Thu, 4 Sep 2008 15:37:42 -0400 (EDT)
Received: from workstation.example.com (workstation.example.com [xx.xxx.xxx.xx]) by server.example.com (Postfix) with ESMTP id B89E1185EB for <emailuser@example.com>; Thu, 4 Sep 2008 15:37:25 -0400 (EDT)
From: <emailuser@example.com>
To: <emailuser@example.com>
Subject: testing a loop
Message-Id: <20080904193728.B89E1185EB@server.example.com>
Date: Thu, 4 Sep 2008 15:37:25 -0400 (EDT)
Message text
and to prevent goldfish from causing havoc on the particular inbox (or mitigating what was already done… and preventing future issues), I added the following PHP:
$addressCheck = substr($address,0,strlen($address)-1);
if ($addressCheck==$email)
{
$log->addLine("Email address from autoresponder table is the same as the intended recipient! Not sending the mail!");
break;
}
just before letting the mail being sent…
I love goldfish. It’s like a do it yourself autoresponder! Keep in mind, this code works on Version 002, patch level 1, but could very well not work on any future releases (there have been indications that a newer version is in the works). Maybe I will post a few more tweaks in upcoming posts if the latest stable stays around for much longer.
Posted by Karl Herrick on September 9th, 2008 in PHP, Linux, Cron | 2 Comments »
Autoresponders - a loop
This past week I encountered an interesting situation between two web applications I work with regularly. The first is the goldfish autoresponder for postfix. The second is RT: Request Tracker.
The situation went something like this:
- I had a ticket in RT that I wanted to resolve.
- I set the form to cc the comment to a group of users who were interested in the details of the resolution.
- I applied the ticket in RT.
- RT cc’ed the users about the resolution.
- One of the users had an autoresponder setup using goldfish, so it emailed back to RT about the user’s absence.
- RT opened a ticket with the content of the email from the autoresponder, faithfully attaching the subject explaining the user’s absence.
- RT then responded to the user’s email account about the new ticket’s creation.
- Again goldfish autoresponds to a message from RT, creating a loop.
Every five minutes a new ticket was being created in RT because of goldfish’s configuration and cron job being set to run that often. I caught the cycle happening when the incoming queue of tickets had three or four created with their subjects typical of those created by an autoresponder.
Posted by Karl Herrick on August 2nd, 2008 in PHP, Linux, Cron | 2 Comments »
Cron crontab window windowed gui app application
The title shows all of the different terms I was googling for… and what was near impossible to find, I finally found.
Here I am to share share my new found knowledge with you. Do you want to run a windowed application with cron? The basics are that you have to export your display.
Yeah, I read that in other places. But where? I thought to myself… Some said, “IN YOUR CRONTAB FILE” Yeah, okay, whatever that means. I would like some more detail. As they say, the devil is in the details. So, with detailed instructions I continue.
If you have your cron permissions setup properly and run:
crontab -e
you can set a cron job that looks something like:
0,30 * * * * export DISPLAY=:0 && killall skype && sleep 5 && skype
So what does this mean? It means, every 30 minutes, run the following commands:
export DISPLAY=:0
killall skype
sleep 5
skype
Okay, difficult to explain… but basically as I understand it, it means: When you run the cron job, it is in a terminal environment. It cannot find the X Windows display without setting the DISPLAY variable within the command string for the cron job.
So, as a recap, set your display variable within the command string of your cron job.
Posted by Karl Herrick on September 8th, 2006 in Cron, Bash | No Comments »