Xref: utzoo comp.sys.att:7635 unix-pc.general:3772 unix-pc.uucp:155 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!dptg!att!shuxd!attdso!galaxia!cals01!cals From: cals@cals01.NEWPORT.RI.US (Charles A. Sefranek) Newsgroups: comp.sys.att,unix-pc.general,unix-pc.uucp Subject: Re: How do you check if ph0 is set to DATA? Summary: phstat and shell script Message-ID: <514@cals01.NEWPORT.RI.US> Date: 23 Sep 89 02:22:49 GMT References: <2938@puff.cs.wisc.edu> <4185@ditka.UUCP> <512@cals01.NEWPORT.RI.US> <985@utoday.UUCP> Reply-To: cals@cals01.Newport.RI.US (Charles A. Sefranek) Distribution: usa Organization: My Very Own Castle, Portsmouth RI Lines: 349 In article <985@utoday.UUCP> comeau@.UUCP (Greg Comeau) writes: >In article <512@cals01.NEWPORT.RI.US> cals@cals01.Newport.RI.US (Charles A. Sefranek) writes: >>In article <4185@ditka.UUCP> kls@ditka.UUCP (Karl Swartz) writes: >>>... >>>I was under the (possibly misguided) impression that due to >>>software bugs ph0 didn't work very well as a data line. >> >>Yup, you're misguided. I *only* use ph0, mostly as a DATA line. > >Care to elaborate on that? I was tol many years ago by several AT&T >people (I know that may not mean anything) that the ph0 harware was >a bit freaky and that I should always use ph1. ... Well, I put my machine on line Oct 1987 and have been using only ph0 since then. I have had problems, but the fix disk solved the un- explained machine lock-ups. The inode bug has bit me several times, too, but hopefully the *next* fixdisk will solve that. I have had NO problems traceable to pho hardware. Many people have asked for phstat, my shell script that I use to control uucico transfers, and any other info I can give them. Here it is ... -----------cut here------------cut here----------cut here------------ #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "shREADME <<'END_OF_README' X=================================== X phstat.c X=================================== X X PHSTAT is called with the device descriptor of the phone Xdevice whose status is desired, ie: X Xphstat /ph0 X Xwill return the status of phone line 0. The status is returned on Xstandard output as a text string indicating the state as follows: X X VOICE-IDLE indicates line is idle in voice mode X X VOICE-ACTIVE indicates line is in voice mode with a X conversation in progress. X X DATA indicates line is data mode. X XCurrently phstat will not detect the RINGING condition as such. I think Xthis is returned as status VOICE-ACTIVE, but I'm not sure. X X PHSTAT will return via an exit(1) if it is called improperly, Xand with an exit(0) otherwise. X X To compile phstat with shared libraries: X Xcc -c -ophstat phstat.c Xld -o phstat phstat.o /lib/crt0s.o /lib/shlib.ifile X X I installed phstat in /usr/local/bin/phstat with user bin, Xgroup bin and permissions 755. X X=================================== X uusites.poll X=================================== X X This file is the shell script I use to initiate the uucp Xconnection to my feed site. There are two things you *HAVE* to Xchange if you want to use this for yourself: X X Change variable SITE to be the name of the site you are calling. X Change variable SITE1 to be the first 6 characters of SITE. X XI put this shell script in /usr/lib/uucp/uusites.poll with user uucp, Xgroup mail, and permissions 755. I modified my crontab file to run this in Xplace of the uudemon.hr script. It is set up so I can also run it as Xan ordinary user for special occasions. X XMy system uses the standard ATT uucp (not HoneyDanBer), and I call my feed Xsite to establish the connection. I also contact only one site. If you Xwant to contact more than one site you will have to modify the script to Xsuit your needs. X X Several important things I have learned in setting this up: X X1) All uucp activity is logged on a file /usr/spool/uucp/LOGFILE. X The standard system setup manages this log file weekly so it X doesn't overflow your disk. Keep an eye on this file regularly X to see what's going on with your uucp connection. Many problems X will first show up here. X X2) If a uucico fails for any reason, it leaves a status file (named X STST laying around in the /usr/spool/uucp directory. X The presence of this file will prevent uucico from attempting a X retry before some default time (usually 1 hour). The script X removes all STST* files from the spool directory to allow a X shorter retry period. X X3) Before you change the state of the phone line, you *must* save X its current status. This is required to decide what to do after X the uucico is completed. Remember that a successful uucp X connection can run for hours! Cron (or you) may invoke this X shell script *several times* during this time period. You X don't want one of these redundant invocations to screw up X a perfectly good phone connection. Uucico will properly X handle multiple invocations of itself, but it doesn't know or X care anything about the phone device. YOU must handle that! X X4) The trap statement is in there to prevent normal things (like X logging out) from messing up a successful connection. It X probably isn't needed if you only run the script from cron, X but I like to be able to run it manually for debugging and X other special occasions (like a power failure right before X cron would normally run it!). The trap protects me from X myself. X X5) The phtoggle program will properly check for all error X conditions regarding the phone line. It won't try to control X it if it is being used by someone else, and it takes care of X all the lock files. Unfortunately, if it does fail for an error X condition it doesn't seem to tell you in a way that can be X detected in the shell script. It just leaves an error window X laying around on the console. That's how I found out what X situations my shell script wasn't handling properly. X X6) I now use a dummy poll file to detect whether or not the uucico X transfer was successful. This is an empty file named so uucico X thinks it is a queued up job waiting to be acted on. When it X discovers the file is empty, it just skips it. This isn't done, X however, until a complete connection has been successfully X established. So, if you had a good connect, the poll file will X disappear. If the connection failed (initially) the poll file X will still be around. If the connection fails after it had X been successfully established, the poll file will also disappear X and the shell script will not retry. This was done at the request X of my feed site, so they can effectively ignore me (by allowing X my login, turning the line around, then killing the connection) X if they have higher priority things to do and don't want my X machine repeatedly beating the door down trying to get in. X This shell script can be painfully persistent in trying to X establish a good connection otherwise! X XGood luck with this. Please let me know if you find any flaws in Xthe above or come across any other problems I haven't seen yet; Xother than that, I make no guarantee or warranty whatsoever for this Xsoftware. Use at your own risk and let the user beware! X X-- X Charlie Sefranek cals@cals01.NEWPORT.RI.US XUUCP: {rayssd,xanth,lazlo,mirror}!galaxia!cals01!cals XAlt.: c4s@rayssdb.ray.com {sun,decuac,gatech,necntc,ukma}!rayssd!rayssdb!c4s END_OF_README if test 5451 -ne `wc -c phstat.c <<'END_OF_phstat.c' X/* X * X * phstat.c A quick hack to get the status of the phone line so X * we can decide whether or not to toggle it. X * X * At home, I have only one line, so when I leave for work X * I want my phone line set to DATA. I run a shell script X * from cron at 7:00 AM, that goes something like this: X * X * X * Status=`/usr/lbin/phstat /dev/ph0` X * X * if [ "$Status" = "VOICE" ] ; then X * /usr/bin/phtoggle X * fi X * X * X * Robert Rodriguez {inhp4|ptsfa}!pttesac!robert X */ X X#include X#include X Xmain( argc, argv ) X Xint argc; Xchar **argv; X X{ X int fd; X struct updata phdata; X X if ( argc != 2 ) X { X printf( "Usage: phstat \n" ); X exit(1); X } X if ( (fd = open( argv[1], O_RDWR | O_NDELAY )) == -1 ) X exit(1); X if ( (ioctl( fd, PIOCGETP, &phdata )) != 0 ) X exit(1); X if ( phdata.c_lineparam & VOICE ) X printf( "VOICE\n" ); X else X printf( "DATA\n" ); X close(fd); X exit(0); X} END_OF_phstat.c if test 936 -ne `wc -c uusites.poll <<'END_OF_uusites.poll' X#-------------------------------------------------------------------------- X# X# Poll known sites for traffic X# X#-------------------------------------------------------------------------- X# X# 27-Jun-88 Modified to only phtoggle if necessary. X# 17-Aug-88 Modified to trap termination to insure DATA line goes back to X# VOICE after manual invocation and logout. X# 20-Aug-88 Modified to use phstat to determine ACTIVE/IDLE status on X# VOICE line. X# 08-Jan-89 Modified to repetitively retry uucico call if previous connection X# failed. Known problems with this implementation: X# After a LOST LINE condition, uustat returns status of the PREVIOUS con- X# versation. X# A successful connection that results in say a half hour conversation X# and then terminates abnormally will retry - it would be better to let X# it go until the next call instead of overrunning the time slot. X# 28-Feb-89 Modified to use a null poll file instead of uustat call to X# determine status of conversation after uucico call. X# 27-Mar-89 Modified to check number of inodes and blocks before doing X# the uucico. Aborts and sends warning message to console and unix.log X# if either is too low. X# 27-Apr-89 Removed debugging stuff used to test null poll file operation. X# Changed retry limit. X# X# Charles A. Sefranek X# cals@cals01.NEWPORT.RI.US X#-------------------------------------------------------------------------- XSITE=smwhere # Change this to the site name you contact XSITE1=smwher # This is SITE truncated to 6 characters XPATH=:/usr/lib/uucp:/bin:/usr/bin XLOGFILE=/usr/spool/uucp/LOGFILE XPOLLFILE=/usr/spool/uucp/C.${SITE1}AD0000 Xcd /usr/lib/uucp Xlimit=12 # Max number of retries Xretry=0 Xwtime=300 # Seconds to wait between retries Xminblks=4000 # Min acceptable number of disk blocks Xmininodes=400 # Min acceptable number of inodes X# X# Find number of blocks and inodes for hard disk X# Xset `df | grep "\/dev\/fp002"` X# X# Send warning to console and unix.log if inodes too low X# Xif [ $5 -lt $mininodes ] Xthen X echo "uusites.poll: Abort - too few inodes \c" >/dev/error X echo "#uusites.poll: Abort - too few inodes \c" >/dev/error X exit 1 Xfi X# X# Send warning to console and unix.log if disk blocks too low X# Xif [ $3 -lt $minblks ] Xthen X echo "uusites.poll: Abort - too few disk blocks \c" >/dev/error X echo "#uusites.poll: Abort - too few disk blocks \c" >/dev/error X exit 2 Xfi Xwhile [ $retry -lt $limit ] Xdo X rm -f /usr/spool/uucp/STST* X status=`/usr/local/bin/phstat /dev/ph0` X trap '' 1 2 3 9 15 X # X # Only toggle if it is voice and it is idle X # VOICE-ACTIVE will be handled by uucico X # X if [ $status = 'VOICE-IDLE' ] X then phtoggle X fi X # X # Create dummy poll file here X # X cp /dev/null $POLLFILE X # X # Initiate the conversation X # X uucico -r1 -s${SITE} X # X # Don't change it if it wasn't toggled before ! X # X if [ $status = 'VOICE-IDLE' ] X then phtoggle X fi X trap 1 2 3 9 15 X # X # Check if a retry is needed X # X if test -f $POLLFILE X then X # Conversation failed - retry X retry=`expr $retry + 1` X sleep $wtime X else X # Conversation succeeded - force exit X retry=`expr $limit + 1` X fi Xdone Xuulog END_OF_uusites.poll if test 3157 -ne `wc -c