I wrote this script because most of my contacts are on LiveJournal and so I have them added to my friends list. Unfortunately, you can't add people to your friends list unless they're on LJ themselves
Instructions:
1) emerge jlj
2) set up jlj to post as root using an LJ that's not your main identity
3) add that identity to your friends list
4) put this script in /etc/cron.hourly and chmod it
5) check your friends list. When someone posts, it will be added (note that existing posts are ignored, because this script is so simple that there's almost nothing that can go wrong. It also makes no attempt to clean up the HTML so you will get some random tags appearing all over the place)
I know this is a bit of a hack but I don't know how to use crontab, so when I was making it, I put it in /etc/cron.hourly, which requires it to be run as root. You will notice that jlj is not designed for use in scripts as it doesn't appear to give exit codes. This is why there's a hack in post() which uses grep to give me an exit status. If anyone wants to take the job of re-writing post() so that it doesn't have to rely on jlj (specifying username and password at the top of the script would be nice), I'd be pleased to change this script and bump up the version number. If anyone wants to do a quick hack for posting to a blogger page or something then post it and I'll add that in there too.
DISCLAIMER: This is only about the 3rd functional script I ever built, so if it sucks, don't blame me
Code: Select all
#!/bin/bash
#version 0.2 allows delayed posting of minor edits until something
#more substantial is added
#version 0.1 simply posted all additions or minor changes including
#jared's view count (religiously every hour for about a week :P )
#start defining variables here
# I think you need to re-define $HOME etc.
export HOME=/root
#add entries to anywhere, and comment out the ones you don't want
#duplicate entries will hopefully not matter, but will end up being
#downloaded multiple times just because I'm too lazy to check for them
#The temporary files are based on an md5sum of the URL, so that I
#don't have to bother with special characters etc. Just hex
#trailing slashes are NOT removed before the md5sum, and neither
#is the index.html part if you include it
blog="
blog="$blog http://www.livejournal.com/users/alsuren/"
#That's my LJ. Obviously there's no point in putting that on the list
#if you're using LJ anyway, but it's an example
blog="$blog "
blog="$blog "
blog="$blog "
blog="$blog "
#State how many lines you want to be added/changed before I post to LJ
lines=3
# all files, including a copy of the blogger HTML page in question will
# be stored in this directory. Make sure you have permissions, and also
# make sure that its not going to get deleted
dir="/root/.lj"
# finished defining variables. Start defining functions
download(){
wget -o /dev/null -O "$dir/blog" "$1"
}
check(){
if [ -f "$dir/$1" ]
then
diff "$dir/$1" "$dir/blog" | grep "^>" | sed -e "s/^>//" > $dir/send
result=`cat $dir/send | grep -c ".*"`
if (( "$result > $lines" ))
then
return 0
else
return 1
fi
else
echo "warning: this blog has not been seen before. Nothing will be posted today" >> $dir/log
mv $dir/blog $dir/$1
return 1
fi
}
post(){
if [ "$?" = "0" ]; then
echo "sending update of $1" >> $dir/log
jlj -s -ne -es "<a href="$1">$1</a>" -bf "$dir/send" | grep -q "item posted"
fi
}
clean(){
if [ "$?" = "0" ]; then
mv "$dir/blog" "$dir/$sum" && rm "$dir/send"
else
echo "posting $1 failed" >> $dir/log
fi
}
#finished defining functions. Now to stick it all together
mkdir -p $dir
date >> $dir/log
for i in $blog
do
download $i
sum=`echo "$i" | md5sum | sed -e "s/ *-//"`
check $sum
post $i
clean $i
done
exit 0
