Jan-Jaap Bakker posted on Tue, 13 Oct 2009 03:10:00 +0200 as excerpted: > if [ "$PANPID" != "" ] > then > echo Pan is allready running, stopping it first... > kill -15 > $PANPID > #this soft kill allows pan to save the current tasks. > else
Depending on your "brand" of "unix", "killall" will likely work better for you. It'll allow you to avoid all that grepping for the pid, etc. You could also avoid the "if" logic that way. If pan's running, it'll kill it, if not, no harm done. Also, at least on normal Linux, SIGTERM is killall's default, so it need not be specified explicitly. The catch of course is that while some unixen (including Linux) use killall as a "string" form of the kill command, some others use it as a literal "kill all", and send pretty much everything the same kill signal, effectively taking down the system. IIANM Solaris works this way. I don't know about the BSDs. So a script using killall wouldn't be 100% portable. Of course, given that bash shebang, it's already not 100% portable, or you'd be using standard sh instead of bash. But if you were aiming for that, you'd probably be using a $PANNZBDOWNLOADDIR environmental variable instead of hardcoding it (either coding some sane default if $PANNZBDOWNLOADDIR isn't set, or exiting with an error or spitting out the --help instructions in that case). Here's a quick hack version, untested because were I to test it, it'd kill this half written message! Talking about... If someone's composing a message in pan, they're not likely to appreciate pan suddenly terminating and the resulting loss of their work, which in my case may be several hundred lines and the work of over an hour. (You can probably imagine my irritation if I took a break from composing this, was browsing, decided an nzb file looked interesting, clicked it, and pan were to exit after I'd half-finished the quick-hack script below... even if it /is/ an "untested quick hack".) So a good solution would check for a compose window, and wouldn't terminate pan if one's active. But this isn't claimed to be a "good" solution, only a quick hack, and an untested one at that. If there were a way to force pan to do the save as draft thing... but I don't believe there is. Meanwhile, relying on the user's good sense not to be trying to add nzb's to pan when they have a compose window open is probably workable enough, if not ideal. Worse comes to worse, they shouldn't make that mistake more than once or twice! (The shebang line, #!... should be the first line. It's shown here as the second after the snip line for post formatting purposes. Also, watch the wrap, if you're reading this in pan, you may need to hit the "w" key, by default toggling the wrap function, to get the lines right.) --------------------8><----------------------------- #!/bin/bash helpme () { cat <<-eoh >$2 $0 syntax: $0 <nzbfile> $0 [-h|--help] Invoke pan to download the contents of <nzbfile> to PANNZBDOWNLOADDIR, see below. If there's not exactly one parameter, a readable file assumed to be an nzbfile, print this help message on STDERR and exit. Script uses and requires one environmental variable, PANNZBDOWNLOADDIR, which should point to a writable directory for pan to write the binaries from the nzb file to. Set and export this in your .bashrc or whatever. If this is unset or doesn't point to a directory, again, script will print this help message to STDERR and exit. WARNING! Script terminates any existing pan before (re)starting it. Download tasks are saved but the contents of any open compose windows will be lost, so take care when invoking! eoh exit 1 } # if there's not exactly one parameter, help/exit [ "$#" = "1" ] || helpme # if that parameter isn't a readable file, help/exit [ -r "$1" ] || helpme # if $PANDOWNLOADDIR doesn't point to a directory, help/exit [ -d "$PANDOWNLOADDIR" ] || helpme killall pan pan -o "$PANNZBDOWNLOADDIR" --nzb "$1" & # so pan isn't sent a SIGHUP when script exits # some multi-processing systems might need a sleep in # here, one side or the other of the disown, as well. # sleep 2 disown -a ------------------------><8---------------------------- -- Duncan - List replies preferred. No HTML msgs. "Every nonfree program has a lord, a master -- and if you use the program, he is your master." Richard Stallman _______________________________________________ Pan-users mailing list Pan-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/pan-users