[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [leafnode-list] suggestion for next version....



On Mon, 16 Aug 1999, Russell J. Romano <rromano@xxxxxxxxxxx> wrote:
> I would like to see a maxtime option.  That would allow me to say
> download everything you can get in 2 hours and then stop.

Someone suggested the killall solution in cron.  Surely that should
work in such cases, but I don't run my personal get-news script out of
cron -- I run it by hand.  Since it also gets mail, I will sometimes
run it (and it drops the connection), I reply to mail and news, and
run get-news again to send out my replies and get new stuff.  Thus, I
can't just have the first one schedule via "at" a kill in 2 hours: it
may kill the next run.

Below is my long and baroque script.  It has some historical survivals
of features I don't need any more; sorry about that, and that makes it
even more useless to others as it currently is written.  The key
features to use as inspiration:

- mysleep.  sleep under the current Linux is aborted by ^Z + CONT!
  It interrupts the system call, I think, and sleep isn't smart enough
  to resume it.  The "trap ... 20" call masks the ^Z off.
- The loggit feature would work if fetch would simply flush its buffers.
- Code of the form
      sh -c "trap '' 20; sleep $timelimit; echo 'TIMEOUT'; kill -INT $$" &
      monitorpid=$!
      trap \
         "set +e;echo KILLED;sleep 3;date;($noconnect||$ppp_down||true);kill $monitorpid;eval $tailkill;exit" \
         0 1 2 3 4 7 8 13
  is what handles timeouts.  monitorpid is a process that sits until a
  time limit passes, and then kills its parent.  However, if the
  parent dies first, it kills monitorpid.  (That kill doesn't kill the
  sleep, for some reason, but it kills everything after it.)  "trap
  ... 0" fires when the script exits normally; the other numbers are
  signal numbers.
- "set -e" makes the script itself exit if any command exits with
  non-zero status.  "||true" while "set -e" is active prevents such an
  exit.
- It also saves all my outgoing articles in a save directory.
- It also makes interesting.groups be equivalent to my .newsrc on each
  run, so there are no timeouts on subscriptions and it doesn't fetch
  unsubscribed groups.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#! /bin/bash
IFS='
'
PATH='/usr/local/bin:/bin:/usr/bin:/etc:/usr/ucb:/usr/5bin:/usr/X11/bin:/usr/andrew/bin:/usr/openwin/bin:/usr/games:/sbin:/usr/sbin:/usr/local/sbin'
SHELL='/bin/bash'

# It's a local call now!  Yippee!
# I have a second line just for data!  Double yippee!
# They limit me to 100 hours a month!  Unyippie.
# timelimit=$[20 * 60]
timelimit=$[3 * 60 * 60] # hours * minutes / hour * seconds / minute

FETCHOPTS=-vv
loggit=false

# Dammit!
function mysleep {
    (trap '' 20 ; sleep "$1")
}

tmcd=~tmcd
MCDANIEL="${MCDANIEL:-$tmcd}"
news=~news
sentbox="$news/sent"

noconnect=false
get_mail=/usr/local/bin/get-mail
while [ $# -gt 0 ]; do
    case "$1" in
        -n) noconnect=true; shift;;  # no dip-crl / dip-out
        -m) get_mail=/bin/true; shift;;  # no mail fetch
    esac
done

file='/var/log/news/get-news'
if $loggit; then
    exec 5>&1
    exec 2>|"$file"
    exec 1>&2
    mysleep 1
fi

# Try to keep the link awake while checking newsgroups.
# Well, not any more. -- It was needed for the old sucking program,
# which would get some information and then sit and think for a
# while.
fingering=false

# ppp_up brings up the link and then returns to the caller when the
# link is up.  It does so using the dip program.  I'm not sure the
# standard PPP scripts do that -- I think the standard start script
# keeps running while the link is up.
ppp_up=/usr/local/bin/jump-up
ppp_down=/usr/local/bin/jump-down
runq=/usr/local/bin/runq
fetch=/usr/local/sbin/fetch

set -x
set -e
if $loggit; then
    tail -f "$file" 1>&5 &
    tailkill="kill $!"
else
    tailkill=':'
fi
# Don't let this script last past the stated time limit.
sh -c "trap '' 20; sleep $timelimit; echo 'TIMEOUT'; kill -INT $$" &
monitorpid=$!
trap \
  "set +e;echo KILLED;sleep 3;date;($noconnect||$ppp_down||true);kill $monitorpid;eval $tailkill;exit" \
    0 1 2 3 4 7 8 13

sync;date
$noconnect || $ppp_up
renice 4 $$
if $fingering
then
    (trap '' 20;while :;do sleep 240;ping -c 1 shell.jump.net>/dev/null;done)&
    wakepid=$!
    # Update this to modern form if using fingering.
    echo DIE DIE DIE FIX YOUR DAMNED CODE BEFORE RUNNING THIS
    exit 223
    trap "set +e;sleep 3; date; $noconnect||$ppp_down||true;kill $wakepid;eval $tailkill;exit;:" \
        0 1 2 3 4 7 8 13
fi

echo 'Try sending all pending e-mail and getting e-mail.'
date
set +e
time "$get_mail"
set -e
if [ `mailq | wc -l` -gt 1 ]
then
    $runq & $runq &
fi

echo 'About to do news fetch (after hacks).'
date

(
    set -x
    # Save copies of all outgoing articles in $sentbox.
    # Also fix my From: lines.
    cd /var/spool/news/out.going && if [ `ls | wc -l` -ne 0 ]; then
        chmod u+w *
        perl -pi -e 's/^(From:.*)tmcd\@tmcd\.austin\.tx\.us/$1tmcd\@jump.net/' *

        cp -f * "$sentbox"
    fi
    set +x
    # Make sure that all subscribed groups in my newsrc are fetched,
    # and only those groups, regardless of any leafnode config
    # timeouts.  -- Spell out the dir to rm explicitly, so no
    # unpleasant defaults are used!
    cd /var/spool/news/interesting.groups && perl -e '
        use strict;
        my $cmd;
        $cmd = "rm /var/spool/news/interesting.groups/*";
        # print $cmd, "\n";
        system($cmd);
        while (<>) {
            chomp;
            s/:.*// or next;
            $cmd = "touch $_";
            # print $cmd, "\n";
            system($cmd);
        }' < "$MCDANIEL/News/.newsrc"
)

$fetch $FETCHOPTS
sync;date
if $fingering
then
    kill $wakepid
fi

# fetch seems to keep doing stuff over the net even after it exits.
mysleep 15

$noconnect || $ppp_down
kill $monitorpid
sync;date
echo EXITING
eval $tailkill

set +x
exit 0


-- 
                   *** NEW HOME E-MAIL ADDRESS ***
Tim McDaniel (home); Reply-To: tmcd@xxxxxxxx; 
if that fail, my work addresses are  tmcd@xxxxxxxxxxxxxx and tmcd@xxxxxxxxxxx
tmcd@xxxxxxxxxxxxxxxxx is a lie; tmcd@xxxxxxx is old and will go away.

-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list