-
Notifications
You must be signed in to change notification settings - Fork 0
/
milinks.sh
executable file
·37 lines (27 loc) · 1023 Bytes
/
milinks.sh
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
#!/bin/bash
PATH=/home/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
export PATH
TMPDIR=/tmp/$$_milinks
die () {
echo "*** Error ***: $@" >&2
exit 1
[ -d $TMPDIR ] && rm -rf $TMPDIR
}
mkdir $TMPDIR
cd $TMPDIR || die "failed to create $TMPDIR"
echo "" > /var/www/milinks.txt
AMAZONLINK=$(amazonlink.php "$1 $2")
if [[ $AMAZONLINK =~ (http.*) ]]; then
CLEANLINK=${BASH_REMATCH[1]}
echo "<strong>(Buy on <a href=\"$CLEANLINK\" target=\"new\">Amazon</a></strong>)" >> /var/www/milinks.txt
fi
QUERY=$(urlencode.sh "$1")
wget -O feed.out http://www.metalinjection.net/?feed=rss2\&s=%22${QUERY}%22 &>/dev/null
xmlstarlet sel --text -t -m "rss/channel/item" -o '» <a href="' -v "link" -o '" target="new">' -v "title" -o '</a><br/>' -n feed.out | head -n3 > links
LINKLINES=$(wc -l links | awk '{print $1}')
if [ $LINKLINES -gt 0 ]; then
echo '<br/><br/>Related Links:<br/>' >> /var/www/milinks.txt
cat links >> /var/www/milinks.txt
fi
cd $HOME
rm -rf $TMPDIR