You are not logged in.
Send commands to 30 computers called lpa-pc-??:
#!/bin/bash
for ((i=1; $i<=30; i++)); do
if [ $i -lt 10 ] ; then
ssh -f root@lpa-pc0$i $1
else
ssh -f root@lpa-pc$i $1
fi
done
get the ssh fingerprints of said computers, so I don't have to type yes thirty times each time ubuntu screws their randdom generator (yes, those computers use ubuntu... and vista *shudder* although the machine with the ssh key is a gentoo)
#!/bin/bash
#for ((i=0; $i<=30; i++)); do ssh-keyscan -p 22 -t rsa,dsa 10.5.40.$(echo 100+$i | bc) 1>> ~/.ssh/known_hosts ; done
for ((i=0; $i<=30; i++)); do
if [ $i -lt 10 ] ; then
ssh-keyscan -p 22 -t rsa,dsa lpa-pc0$i 10.5.40.$(echo 100+$i | bc) 1>> ~/.ssh/known_hosts
else
ssh-keyscan -p 22 -t rsa,dsa lpa-pc$i 10.5.40.$(echo 100+$i | bc) 1>> ~/.ssh/known_hosts
fi
done
Offline
About Common Lisp....are you also Emacs or Stumpwm user? I'm really fascinated about the idea of changing my working environment in real time.
I would like to learn more about it.
I'm an Emacs user, but I haven't tried Stumpwm, which is something I'll have to do some time. It's an interesting language.
Offline
I'm considering rewriting some of my utilities in Common Lisp as a learning exercise...
Its an interesting language indeed, though using Common Lisp to write a simple script is, quite frankly, gratuitous overkill. For scripting, scheme is better suited.. theres even a shell based on it, scsh, which might better suit your needs as it provides all the functionality of a shell scripting language though doing it in a lispy manner, and thus might help getting into the mindset of writing lisp code. Anyways, Common Lisp is better suited for large, complex applications/systems.. though if you insist, go ahead, though its unlikely to prove much of an exercise in CL coding as you most likely wouldn't utilize most of the capabilities that make it such an interesting language, ie metaprogramming, CLOS, etc. in order to slap a few shell utilities together.
Waffles?
Offline
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...
Offline
I always suspected that!
Last edited by ArchArael (2008-10-13 22:00:26)
Offline
Waffles?
Offline
moljac024 wrote:I always suspected that!
That actually explains a lot of the messy results we are witnessing today.
*dogdes objects thrown by perl-programmers*
Offline
here is one i made (its not the best) for a make-do video library thingi...
#!/bin/bash
fuser -k /dev/dsp*
fuser -k /dev/dsp
echo ""
find -L "/home/tharihar/Videos//" -depth -iname "*$1*$2*$3*" ! -iname *.jpg>.playmovies
#cat .playmovies
mplayer -shuffle -really-quiet -playlist .playmovies>/dev/null
rm .playmovies
echo ""
here is one to convert .deb or .rpm to .pkg.tar.gz
#!/bin/bash
mkdir k
cd k
pkgextract.sh $1.deb
cd ..
mv k/ pkg/
echo "pkgname="$1>>PKGBUILD
echo "pkgver="$2>>PKGBUILD
echo "pkgrel=1">>PKGBUILD
echo "arch=(i686)">>PKGBUILD
echo "build()">>PKGBUILD
echo "{">>PKGBUILD
echo "echo "Building package"">>PKGBUILD
echo "}">>PKGBUILD
makepkg -R
cd ..
rm -rf pkg
that one uses pkgextract from aur i think (not my pkg).
here is one for writing Lec files, it takes input of course name and number (eg PHIL 400) and opens up vim with a tex file, and compiles it into pdf aafter i quit and displays pdf for me. The reason for this is so that i do not have to browse to the folder everytime, plus I have a universal template kinda file (called lec.tex) that I put stuff that i wanna start off with.
#!/bin/bash
#definitions
Today=`date +%b%d`
FileName=`echo "Lec_"$Today`
FilePlainPath="/home/tharihar/.bookmarks/Notes: Current/"$1\ $2/
export FilePath="/home/tharihar/.bookmarks/Notes: Current/"$1\ $2/$FileName.tex
#change directory
cd "$FilePlainPath"
if [ -e "$FilePath" ]
then
echo "file already exists"
else
cp ~/Notes/lec.tex "$FilePath"
fi
vim "$FilePath"
latex "$FilePath"
cp "$FilePath" "$FilePlainPath/.Lec"
rm *.aux
rm *.log
rm *.nav
rm *.out
rm *.snm
rm *.toc
rm *.vrb
dvips $FileName.dvi
ps2pdf $FileName.ps
rm *.ps
xpdf $FileName.pdf
I have another one for my essay but this one uses essay.tex and essay.bib and does latex-> bibtex-> latex-> latex before doing dvips etc.
here is the thing i use to output to dwm... (status bar)
#!/bin/bash
while true
do
echo -e `/home/tharihar/.Bin/Info` "|" `date +"%a, %b %d"` "|" `date +"%T %p"` "| Upgradable:" `cat /home/tharihar/.tobeupgraded` "|" `cat /proc/acpi/thermal_zone/THM/temperature|gawk '/temp/ {print $2}'`"\xb0C"
done
and here is Info: (seperate siince i sometimes like to call it from CLI when i am only working with CLI without any X
#!/bin/bash
#export MPD_HOST=TjsLaptop
#export MPC_PORT=65000
tit=$(mpc | awk '/-/ {print $0}')
textp=$(mpc | gawk '/play/ {print $3,$4}')
len=${#tit}
text=""
if [ "${#textp}" -eq 0 ] #//paused
then
text="*Paused* "
fi
echo -n "Now Playing: "
################################
if [ "$len" -eq 0 ]
then ####not playin mpc
flag=0
mpstat=$(pgrep -d ' ' mplayer)
if [ `pgrep Play` ] #watching anime
then
if [ `expr index "$mpstat" " "` -eq 0 ];then #only Play running.
lsof -p $mpstat -a +D /media/EXTERNAL/ | gawk --field-separator='/' '/EXTERNAL/ {print $NF}'
else #play +i one more mplayer
lsof -p $mpstat -a +D /media/EXTERNAL/ 2>/dev/null | gawk --field-separator='/' '/EXTERNAL/ {print $NF}'
pos=$(expr index "$mpstat" " ")
lsof -p ${mpstat:pos} -a +D /media/EXTERNAL/ | gawk --field-separator='/' '/EXTERNAL/ {print $NF}'
echo ", Porn"
fi
flag=1 #1 for anime.
elif [ `pgrep mplayer` ] ##no Play + porn
then
echo -n "Porn"
flag=2 #2 for porn
else
echo -n ""
fi
##########Nothing is Playing###################33
if [ $flag -eq 0 ] #nothing is playing
then
echo -n "None"
fi
###end crazy if's, mpc##########
elif [ `expr match "$tit" "D I G I T A L L Y"` -eq 0 ]
then
##playing music##
echo -e $tit ' ' '[' $textp $text']'
else
##playing radio##
tit=$(mpc | gawk --field-separator=':' '/-/ {print $(NF - 0)} ')
textp="$(mpc | gawk '/play/ {print $1"/"$3,$4}' | gawk --field-separator='/' '/play/ {print $(NF - 1)}') *Radio*"
echo -n -e $tit ' ' '[' $textp $text ']'
fi
that one is extremely involved and basically gives the now playing status (including video etc). It works best if you use with the 'Play' script, since I play everything all my regular videos (aka not porn) using Play and everything else (aka porn) using just mplayer (start it from nautilus etc). I also use mpd for radio which has a bit of extra adverrtisement junk at the begining of the title (the extensive expr match and the gawk is for that).
-Tj
Last edited by TjPhysicist (2008-10-14 06:59:32)
-Tj
Now reborn as Tjh_ (to keep it similar to my username in other places)
Offline
Dmenu script for changing wallpaper with Feh or Nitrogen:
#!/bin/sh
#current=`awk '{gsub (/\/home\/joe\/wallpapers\//, ""); print $3}' ~/.fehbg`
current=`awk '/file/ {gsub (/file=\/home\/joe\/wallpapers\//, ""); print $1}' ~/.config/nitrogen/bg-saved.cfg`
cmd=$(ls ~/wallpapers | dmenu -p $current)
if [ -f ~/wallpapers/$cmd ]; then
#feh --bg-scale ~/wallpapers/$cmd
nitrogen --set-scaled ~/wallpapers/$cmd --save
fi
Playing albums with MPD:
#!/bin/sh
cmd=$(mpc ls | dmenu)
if [ -d ~/music/"$cmd" ]; then
mpc clear & mpc add "$cmd"
mpc play
fi
Editing scripts and config files with Leafpad:
#!/bin/sh
configs()
{
echo "rc.xml (config)
menu.xml (config)
autostart.sh (config)
tintrc (config)
conkyrc (config)
gtkrc-2.0 (config)
xinitrc (config)
rtorrentrc (config)
bashrc (config)
awesomerc (config)
xdefaults (config)
irssi (config)
abcde.conf (config)
fonts.conf (config)
screenrc (config)
rc.conf (config)
xorg.conf (config)
mpd.conf (config)
inittab (config)
fstab (config)
hosts (config)
hosts.allow (config)
hosts.deny (config)
ssh_config (config)
sshd_config (config)
pacman.conf (config)
makepkg.conf (config)
rc.wmii (config)
wmiirc (config)"
for name in ~/.scripts/*
do
echo "$name (script)"
done
}
dmenu=`configs | awk '!/.png|.log|.txt/ {gsub (/\/home\/joe\/.scripts\//, ""); print}'`
cmd=$(echo -n "$dmenu" | dmenu)
case ${cmd} in
rc.xml*) exec leafpad ~/.config/openbox/rc.xml &;;
menu.xml*) exec leafpad ~/.config/openbox/menu.xml &;;
autostart.sh*) exec leafpad ~/.config/openbox/autostart.sh &;;
tintrc*) exec leafpad ~/.config/tint/tintrc &;;
conkyrc*) exec leafpad ~/.conkyrc &;;
gtkrc-2.0*) exec leafpad ~/.gtkrc-2.0 &;;
xinitrc*) exec leafpad ~/.xinitrc &;;
rtorrentrc*) exec leafpad ~/.rtorrent.rc &;;
bashrc*) exec leafpad ~/.bashrc &;;
awesomerc*) exec leafpad ~/.awesomerc &;;
xdefaults*) exec leafpad ~/.Xdefaults &;;
irssi*) exec leafpad ~/.irssi/config &;;
abcde.conf*) exec leafpad ~/.abcde.conf &;;
fonts.conf*) exec leafpad ~/.fonts.conf &;;
screenrc*) exec leafpad ~/.screenrc &;;
rc.conf*) exec gksudo leafpad /etc/rc.conf &;;
xorg.conf*) exec gksudo leafpad /etc/X11/xorg.conf &;;
mpd.conf*) exec gksudo leafpad /etc/mpd.conf &;;
fstab*) exec gksudo leafpad /etc/fstab &;;
inittab*) exec gksudo leafpad /etc/inittab &;;
hosts.allow*) exec gksudo leafpad /etc/hosts.allow &;;
hosts.deny*) exec gksudo leafpad /etc/hosts.deny &;;
hosts*) exec gksudo leafpad /etc/hosts &;;
ssh_config*) exec gksudo leafpad /etc/ssh/ssh_config &;;
sshd_config*) exec gksudo leafpad /etc/ssh/sshd_config & ;;
pacman.conf*) exec gksudo leafpad /etc/pacman.conf &;;
makepkg.conf*) exec gksudo leafpad /etc/makepkg.conf &;;
rc.wmii*) exec gksudo leafpad /etc/wmii-3.5/rc.wmii &;;
wmiirc*) exec gksudo leafpad /etc/wmii-3.5/wmiirc &;;
*script*) exec leafpad ~/.scripts/${cmd} &;;
*) exec leafpad "$cmd" &;;
esac
Offline
Something I wrote yesterday, may be useful for someone
#!/bin/bash
#
# gov-tool
#
# Randy Morris (rson)
#
# script to adjust cpufreq governor
# meant to be used with hotkeys, originally for use with dwm
#
# NOTE: makes the assumption that this is a dual core machine
# and both cores are using the same governor
#
# CREATED: 2008-10-13 20:32
# MODIFIED: 2008-10-13 21:31
USAGE="\ngov-tool <ACTION> [GOVERNOR]\n\
ACTIONS:\n
-i, --increase\t\t\tset governor to a more power hungry governor\n\
-d, --decrease\t\t\tset governor to a less greedy governor\n\
-s, --set <governor>\t\tset <governor> as the current governor\n"
CUR=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
ACT="die"
OPTS=$(getopt -o ids: --long increase,decrease,set: -- $@)
eval set -- "$OPTS"
while true
do
case $1 in
-i|--increase) ACT="up"; break;;
-d|--decrease) ACT="down"; break;;
-s|--set) ACT="set"; GOV=$2; break;;
--) break;;
*) echo "error: option parsing is broken"; exit 1;;
esac
done
[ $ACT == "die" ] && echo "error: you must specify an action" && echo -e $USAGE && exit 1
if [[ ! $ACT == "set" ]]
then
case $CUR in
"performance")
if [[ $ACT == "up" ]]
then
echo "error: highest performing governor is already set"
exit 1;
else
GOV="ondemand"
fi
;;
"ondemand")
if [[ $ACT == "up" ]]
then
GOV="performance"
else
GOV="conservative"
fi
;;
"conservative")
if [[ $ACT == "up" ]]
then
GOV="ondemand"
else
GOV="powersave"
fi
;;
"powersave")
if [[ $ACT == "up" ]]
then
GOV="conservative"
else
echo "error: most conservative governor already set"
exit 1
fi
;;
esac
fi
echo "setting $GOV governor"
cpufreq-set -c0 -g $GOV
cpufreq-set -c1 -g $GOV
exit 0
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
up ()
{
[[ $# -eq 0 ]] && cd ..
if [[ $1 =~ ^[0-9]+$ ]] && [[ $1 -gt 0 ]]
then
dirs=1
until [[ $dirs -gt $1 ]]
do
command="${command}../"
dirs=$(($dirs+1))
done
cd $command
command=''
fi
}
'up' is the same as 'cd ..'
'up 2' is the same as 'cd ../..'
'up 3' is the same as 'cd ../../..'
etc etc
this is probably written really badly tho
flack 2.0.6: menu-driven BASH script to easily tag FLAC files (AUR)
knock-once 1.2: BASH script to easily create/send one-time sequences for knockd (forum/AUR)
Offline
@dyscoria: That's a useful one. Also fun to look for an optimization. How about: up() { for updirs in $(seq ${1:-1}); do cd ..; done; }
Offline
get the ssh fingerprints of said computers, so I don't have to type yes thirty times each time ubuntu screws their randdom generator
I this command might be helpfull for you
ssh -o "StrictHostKeyChecking=no"
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
Kill gnome-screensaver before starting mplayer
#!/usr/bin/env python import os import os.path import sys os.system("killall gnome-screensaver") command = '/usr/bin/mplayer %s "%s"' % (' '.join(sys.argv[1:-1]), os.path.normpath(sys.argv[-1])) os.system(command) os.system("gnome-screensaver")
I still do not understand the "command =" line but it works
Just an FYI. xscreensaver has a -disable command that disables the screensaver for some time. You can use that with mplayer's "heartbeat-cmd" setting - might be cleaner to do it that way
Offline
moljac024 wrote:
The comments, . It's always the same ...
Offline
To keep track of what I'm doing all the time with my computer - it needs to be polished a lot and rewritten in Java as my college "homework" :
cat /usr/local/bin/achievo
#!/bin/bash
# script achievo
# author: dante4d <dante4d@gmail.com>
DATABASE="$HOME/.achievo"
function usage() {
BASENAME="`basename $0`"
echo "Usage: $BASENAME <command> [arguments]"
echo " commands:"
echo " start project [task]"
echo " stop"
echo " print"
echo
exit 1
}
case $1 in
'start')
PROJECT=$2
if [[ -z "$PROJECT" ]]; then
echo 'Missing project'
usage
fi
TASK=${3:-"-"}
echo -e "`date '+%y/%m/%d'`\t`date '+%H:%M:%S'`\t$PROJECT\t$TASK" >> $DATABASE
;;
'stop')
echo -e "-\t`date '+%H:%M:%S'`\t-\t-" >> $DATABASE
;;
'print')
cat "$DATABASE"
echo
;;
*)
usage
esac
exit 0
Last edited by dante4d (2008-10-14 18:53:51)
Offline
Here are a few really, really stupid ones. I'm using kdialog for information display.
lidsusp
Sometimes, I like my laptop to suspend when I close my lid. Sometimes, I don't. The control script:
#!/bin/bash
case $1 in
on|1|true)
echo 1 > ~/.lidsusp
lidsusp check
;;
off|0|false)
echo 0 > ~/.lidsusp
lidsusp check
;;
check|get)
if [ $(cat ~/.lidsusp) == "1" ] ; then
STATUS="Enabled"
else
STATUS="Disabled"
fi
kdialog --msgbox "Suspend on Lid Close $STATUS"
;;
esac
The event in /etc/acpi/handler.sh:
button/lid)
if grep -q 1 /home/j/.lidsusp ; then
if grep -q closed /proc/acpi/button/lid/LID/state ; then
echo mem > /sys/power/state
fi
fi
;;
This is only useful if you're the only user, obviously.
Battery status:
#!/bin/bash
STATUS=`acpi | cut -d " " -f 8 | sed s/,//g`
BATTLF=`acpi | cut -d " " -f 9 | sed s/,//g`
TIMERM=`acpi | cut -d " " -f 10 | sed s/,//g`
DIALOG="status : $STATUS
remaining : $BATTLF
time left : $TIMERM"
kdialog --msgbox "$DIALOG"
Some monitor controls (used to quickly change between on and off, single and dual displays):
[j@jwcxz Scripts]$ cat mon
#!/bin/bash
# monitor controls
newmode=$1
case $newmode in
one|1)
#echo "single monitor"
xrandr --dpi 96 --output VGA --off
;;
two|2)
#echo "dual monitors"
xrandr --dpi 96 --output VGA --size 1280x1024 --preferred --right-of LVDS
;;
auto)
if xrandr -q | grep VGA | grep " connected" > /dev/null ; then
mon 2
else
mon 1
fi
;;
off)
xset dpms force off
;;
on)
xset dpms force on
;;
esac
Switch between QWERTY and Dvorak layouts:
case $1 in
switch)
if [ "$(cat ~/.keymap)" == "qwerty" ] ; then
kbd dvorak
else
kbd qwerty
fi
;;
dvorak)
xmodmap ~/Arch/keymaps/dvorak.pke
echo "dvorak" > ~/.keymap
;;
qwerty | aaa)
xmodmap ~/Arch/keymaps/qwerty.pke
echo "qwerty" > ~/.keymap
;;
check)
if [ "$(cat ~/.keymap)" == "qwerty" ] ; then
STATUS="QWERTY"
else
STATUS="Dvorak"
fi
kdialog --msgbox "Keyboard Layout: $STATUS"
;;
*)
kbd check
esac
Yeah, stupid, I know. But they're useful for me.
-- jwc
http://jwcxz.com/ | blog
dotman - manage your dotfiles across multiple environments
icsy - an alarm for powernappers
Offline
I had a dream like that last night, it was really weird.
Offline
mine is pretty lame in comparsion to you guys but it helps me fixing my fonts when I'm using the external monitor in eeePC
#!/bin/bash
#ajusta tamanho das fontes no gnome dependendo da resolucao escolhida
resol=`xrandr | grep "+0+0"| awk {'print $3'} |cut -d"x" -f1`
if [ $(($resol / 100)) -gt 9 ]; then
gconftool-2 --set /apps/nautilus/preferences/desktop_font --type string "Sans 12"
gconftool-2 --set /desktop/gnome/interface/document_font_name --type string "Sans 12"
gconftool-2 --set /desktop/gnome/interface/font_name --type string "Sans 12"
gconftool-2 --set /apps/metacity/general/titlebar_font --type string "Sans Bold 12"
gconftool-2 --set /desktop/gnome/interface/monospace_font_name --type string "Monospace 12"
echo "fontes setadas com tamanho 12"
else
gconftool-2 --set /apps/nautilus/preferences/desktop_font --type string "Sans 8"
gconftool-2 --set /desktop/gnome/interface/document_font_name --type string "Sans 8"
gconftool-2 --set /desktop/gnome/interface/font_name --type string "Sans 8"
gconftool-2 --set /apps/metacity/general/titlebar_font --type string "Sans Bold 8"
gconftool-2 --set /desktop/gnome/interface/monospace_font_name --type string "Monospace 10"
echo "fontes setadas com tamanho 8"
fi
Offline
mine is pretty lame in comparsion to you guys but it helps me fixing my fonts when I'm using the external monitor in eeePC
Have you tried adjusting the DPI settings instead? You can do that with xrandr.
-- jwc
http://jwcxz.com/ | blog
dotman - manage your dotfiles across multiple environments
icsy - an alarm for powernappers
Offline
Allan wrote:Kill gnome-screensaver before starting mplayer
#!/usr/bin/env python import os import os.path import sys os.system("killall gnome-screensaver") command = '/usr/bin/mplayer %s "%s"' % (' '.join(sys.argv[1:-1]), os.path.normpath(sys.argv[-1])) os.system(command) os.system("gnome-screensaver")
I still do not understand the "command =" line but it works
Just an FYI. xscreensaver has a -disable command that disables the screensaver for some time. You can use that with mplayer's "heartbeat-cmd" setting - might be cleaner to do it that way
I didn't know about the heartbeat-cmd option. That it a better way to deal with this.... For gnome-screensaver: add heartbeat-cmd "gnome-screen-saver-command -p" to the mplayer config file
Offline
joqueza wrote:mine is pretty lame in comparsion to you guys but it helps me fixing my fonts when I'm using the external monitor in eeePC
Have you tried adjusting the DPI settings instead? You can do that with xrandr.
Yeah I tried that but the ratio pixel/font size didn't look right to me, dunno.... but who am I to argue about coding
Offline
Here is my backup script. It's designed for daily use and saves the backups in a directory named after the date. It works with hardlinks, so there is a directory for every day, but not that much disk space is used.
#!/bin/bash # Edit parameters here. # Important: Don't forget the trailing slashes in SOURCES and TARGET SOURCES="/etc/ /boot/ /home/rine/" TARGET="/media/e/archbackup/" OPTIONS="--exclude-from=/home/rine/documents/scripts/exclude.list" ### Don't edit below ### LASTBACKUP=`ls -d $TARGET* | sort -r | head -1` TODAY=`date +%y%m%d` if [ "$LASTBACKUP" == "$TARGET$TODAY" ]; then echo "Backup for today is done, if there were errors, delete $TARGET$TODAY first" exit 1 fi for src in $SOURCES do if [ "$LASTBACKUP" ]; then LD="--link-dest=$LASTBACKUP$src" fi mkdir -p $TARGET$TODAY$src rsync -auv $OPTIONS $LD $src $TARGET$TODAY$src done
When you want to exclude files, it's important to start them with a slash in exclude.list. If, for example, you want to exclude your "movies" directory, you type /movies. Otherwise, if you happened to have a file called movies somewhere else, it also would get excluded. Example exclude.list:
/.adobe /.alsaplayer /.cache /.dbus /.fontconfig /.gstreamer-0.10 /.java /.local /.macromedia /.mcop /.mozilla /.openoffice.org2 /.qt /.quodlibet /.session /.texlive /.texmf-var /.thumbnails /.xine /serien /tmp
Comments for improvement welcome.
Thanks for the code I modified it a bit so that it would tar and compress the folder created, then delete the folder afterwards. Thanks for making backing up so much easier.
There is a difference between bleeding [edge] and haemorrhaging. - Allan
Offline
I modified it a bit so that it would tar and compress the folder created, then delete the folder afterwards.
I found that for my system, dar is much faster and also allows for things like differential backups.
-- jwc
http://jwcxz.com/ | blog
dotman - manage your dotfiles across multiple environments
icsy - an alarm for powernappers
Offline
This is a fun little one, not really a system utility, but an entertainment one. Simple bash script that will retrieve the latest comic from dilbert.com, name it to something meaningful, and save it to a directory of your choosing. It runs as a cron job at 5:45AM daily.
Probably not the most efficient, but it has gotten the job done without complaint for quite some time now.
#!/bin/bash
#
# Script to download the daily dilbert.com comic.
# Created by Tim Lofgren.
# Revision Date: August 28, 2008
### VARIABLE DECLARATION
# Define the temporary and archive directories.
# Unless they change their website, this is all that
# should need adjusting.
tmpdir=/tmp
archivedir=/home/httpd/html/dilbert
# Define Dilbert webpage URL (no trailing slash).
dilberturl=http://dilbert.com
# Define leading section of dilbert.com's image storage location
# This is found by snooping through the page source
stripident=/dyn/str_strip/
### SCRIPT
# Make sure no files exist that could screw things up.
rm -f $tmpdir/index.html*
# Get the index.html file.
wget -q -P $tmpdir $dilberturl
# Search the index.html file for the daily comic URL.
dilbertext=`grep $stripident $tmpdir/index.html`
# Filter out the unique number and file extension.
dilbertext=${dilbertext##*img\ src=\"}
dilbertext=${dilbertext%%\"*}
# Download the daily comic.
# Rename it to something meaningful and place it in the archive directory.
# Weekdays are in .gif format, Sundays are in .jpg format. <--this is now old.
# This checks the file type and acts accordingly...
dilbertextf=${dilbertext##*.}
if [ $dilbertextf == gif ]; then
wget -q -O $archivedir/dilbert`date +%Y%m%d`.gif $dilbertext
elif [ $dilbertextf == jpg ]; then
wget -q -O $archivedir/dilbert`date +%Y%m%d`.jpg $dilbertext
else
exit 1
fi
# Remove the index.html file.
rm -f $tmpdir/index.html
exit 0
Offline