Author: jsmeix
Date: Fri Jul 2 17:00:03 2010
New Revision: 62178
URL: http://svn.opensuse.org/viewcvs/yast?rev=62178&view=rev
Log:
Enhanced the test_* tools to do the most meaningful test first
so that ICMP echo (ping) is no longer required in any case
(see Novell/Suse Bugzilla bnc#616706).
This is an enhancement for after openSUSE 11.3
Increased VERSION to 2.19.14
Modified:
trunk/printer/VERSION
trunk/printer/package/yast2-printer.changes
trunk/printer/tools/test_remote_ipp
trunk/printer/tools/test_remote_lpd
trunk/printer/tools/test_remote_novell
trunk/printer/tools/test_remote_smb
trunk/printer/tools/test_remote_socket
Modified: trunk/printer/VERSION
URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/VERSION?rev=62178&r1=62177&r2=62178&view=diff
==============================================================================
--- trunk/printer/VERSION (original)
+++ trunk/printer/VERSION Fri Jul 2 17:00:03 2010
@@ -1 +1 @@
-2.19.13
+2.19.14
Modified: trunk/printer/package/yast2-printer.changes
URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/package/yast2-printer.changes?rev=62178&r1=62177&r2=62178&view=diff
==============================================================================
--- trunk/printer/package/yast2-printer.changes (original)
+++ trunk/printer/package/yast2-printer.changes Fri Jul 2 17:00:03 2010
@@ -1,4 +1,12 @@
-------------------------------------------------------------------
+Thu Jul 1 17:33:47 CEST 2010 - jsmeix@suse.de
+
+- Enhanced the test_* tools to do the most meaningful test first
+ so that ICMP echo (ping) is no longer required in any case
+ (see Novell/Suse Bugzilla bnc#616706).
+- 2.19.14
+
+-------------------------------------------------------------------
Wed Jun 23 15:59:44 CEST 2010 - jsmeix@suse.de
- In autodetect_print_queues replace each " character by \" in
Modified: trunk/printer/tools/test_remote_ipp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/tools/test_remote_ipp?rev=62178&r1=62177&r2=62178&view=diff
==============================================================================
--- trunk/printer/tools/test_remote_ipp (original)
+++ trunk/printer/tools/test_remote_ipp Fri Jul 2 17:00:03 2010
@@ -2,16 +2,19 @@
#
# Test ability to connect to remote IPP server.
#
-# Exits: 0 doesn't seem to have a problem
-# 1 remote host $1 or queue $2 not set
-# 2 the remote host $1 is unreachable (network issue or firewall active?)
-# 3 no connection possible to port 631 on host $1 (no cups server running there or firewall active there?)
-# 4 queue does not accept a print job (queue may not exist or queueing disabled?)
-# 10 ping not executable (no iputils RPM installed?)
-# 11 netcat not executable (no netcat RPM installed?)
+# Exits: 0 queue on host accepts print jobs
+# 1 host $1 or queue $2 not set
+# 2 no connection possible to port 631 on host and host does not respond to a 'ping'
+# 3 no connection possible to port 631 on host but host responds to a 'ping'
+# 4 connection possible to port 631 on host but queue does not accept a print job
+# (queue may not exist or queueing disabled?)
+# 10 no connection possible to port 631 on host and ping not executable (no iputils RPM installed?)
+# 11 give up empty-handed because netcat not executable (no netcat RPM installed?)
# (12=fuser,13=mktemp,14=sed: see listen_remote_ipp)
-# 15 lp not executable (no cups-client RPM installed?)
+# 15 connection possible to port 631 on host but lp not executable (no cups-client RPM installed?)
+# 16 queue on host does not accept print jobs but lpstat not executable (no cups-client RPM installed?)
# The program head is in the coreutils RPM and therefore assumed to exist.
+# The program rpm is assumed to exist and even if not it triggers only a non-matching warning message.
#
# Johannes Meixner , 2000, 2002, 2007, 2008, 2009, 2010
# Jan Holesovsky , 2000
@@ -28,14 +31,6 @@
# Disable bash file name globbing:
set -f
-# Use the binaries of the operating system (no aliases, functions, /usr/local/):
-export PING=$( type -ap ping | head -n 1 )
-[ -z "$PING" ] && { echo -en "\nping not executable (no iputils RPM installed?)\n" 1>&2 ; exit 10 ; }
-export NETCAT=$( type -ap netcat | head -n 1 )
-[ -z "$NETCAT" ] && { echo -en "\nnetcat not executable (no netcat RPM installed?)\n" 1>&2 ; exit 11 ; }
-export LP=$( type -ap lp | head -n 1 )
-[ -z "$LP" ] && { echo -en "\nlp not executable (no cups-client RPM installed?)\n" 1>&2 ; exit 15 ; }
-
MY_NAME=${0##*/}
HOST="$1"
QUEUE="$2"
@@ -43,15 +38,70 @@
TIMEOUT="$3"
[ -z "$TIMEOUT" ] && TIMEOUT=10
-# test whether the remote host is accessible
-$PING -c 1 -w $TIMEOUT $HOST || { echo -en "\nHost $HOST unreachable (network issue or firewall active?)\n" ; exit 2 ; }
-
-# test whether connection is possible to port 631 (ipp) on the remote host
-$NETCAT -w $TIMEOUT -z $HOST 631 || { echo -en "\nNo connection possible to port 631 (IPP) on host $HOST (no cups server running there or firewall active there?)\n" ; exit 3 ; }
+# Use the binaries of the operating system (no aliases, functions, /usr/local/):
+export PING=$( type -ap ping | head -n 1 )
+export NETCAT=$( type -ap netcat | head -n 1 )
+export LP=$( type -ap lp | head -n 1 )
+export LPSTAT=$( type -ap lpstat | head -n 1 )
-# test whether the queue on the server accepts print jobs
-echo -en "\r" | $LP -d $QUEUE -h $HOST 2>&1
-[ "$?" = "0" ] && { echo -en "\nQueue $QUEUE on host $HOST accepts print jobs\n" ; exit 0 ; }
-echo -en "\nQueue $QUEUE on host $HOST does not accept print jobs (queue may not exist or queueing disabled?)\n"
+# Test whether netcat is executable:
+if test -z "$NETCAT"
+then # Give up empty-handed when netcat is not executable because only the ping test is meaningless:
+ echo -en "\nGiving up empty-handed because 'netcat' not executable (no 'netcat' RPM installed?)\n" 1>&2
+ exit 11
+fi
+# Test whether connection is possible to port 631 on host:
+if ! $NETCAT -w $TIMEOUT -z $HOST 631
+then # The netcat test failed:
+ echo -en "\nNo connection possible to IPP port 631 on host '$HOST' (no server running or firewall active there?)\n\n"
+ # Test whether ping is executable:
+ [ -z "$PING" ] && { echo -en "\n'ping' not executable (no 'iputils' RPM installed?)\n" 1>&2 ; exit 10 ; }
+ # Test whether host is accessible:
+ if $PING -c 1 -w $TIMEOUT $HOST
+ then # The ping test was successful but the netcat test failed:
+ echo -en "\nHost '$HOST' is accessible (responds to a 'ping')\n"
+ exit 3
+ fi
+ # Both the netcat test and the ping test failed:
+ echo -en "\nHost '$HOST' unreachable (network issue or wrong host or firewall active?)\n"
+ exit 2
+fi
+
+# The netcat test succeeded:
+echo -en "\nConnection possible to IPP port 631 on host '$HOST'\n"
+
+# Test whether lp is executable:
+if test -z "$LP"
+then echo -en "\nFailed to test if queue '$QUEUE' on host '$HOST' accepts print jobs" 1>&2
+ echo -en "\nbecause 'lp' not executable (no 'cups-client' RPM installed?)\n" 1>&2
+ exit 15
+fi
+# Warn if lp is not from the cups-client RPM e.g. from self-compiled CUPS (o.k.) or e.g. from LPRng (bad):
+if ! rpm -qf "$LP" | grep -q '^cups-client'
+then echo -en "\nIt may fail to test if queue '$QUEUE' on host '$HOST' accepts print jobs"
+ echo -en "\nbecause '$LP' is not the expected one from the 'cups-client' RPM\n"
+fi
+# Test whether the queue on the server accepts print jobs:
+echo -en "\nTesting queue '$QUEUE' on host '$HOST':\n"
+if echo -en "\r" | $LP -d $QUEUE -h $HOST 2>&1
+then echo -en "\nQueue '$QUEUE' on host '$HOST' accepts print jobs\n"
+ exit 0
+fi
+echo -en "\nQueue '$QUEUE' on host '$HOST' does not accept print jobs (queue may not exist or queueing disabled?)\n"
+# If queue on host does not accept jobs, print queue status:
+# Test whether lpstat is executable:
+if test -z "$LPSTAT"
+then echo -en "\nFailed to determine the status of queue '$QUEUE' on host '$HOST'" 1>&2
+ echo -en "\nbecause 'lpstat' not executable (no 'cups-client' RPM installed?)\n" 1>&2
+ exit 16
+fi
+# Warn if lpstat is not from the cups-client RPM e.g. from self-compiled CUPS (o.k.) or e.g. from LPRng (bad):
+if ! rpm -qf "$LPSTAT" | grep -q '^cups-client'
+then echo -en "\nIt may fail to determine the status of queue '$QUEUE' on host '$HOST'"
+ echo -en "\nbecause '$LPSTAT' is not the expected one from the 'cups-client' RPM\n"
+fi
+echo -en "\nStatus of the queue '$QUEUE' (possibly empty or not available):\n\n"
+$LPSTAT -h $HOST -a $QUEUE -p $QUEUE
exit 4
+
Modified: trunk/printer/tools/test_remote_lpd
URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/tools/test_remote_lpd?rev=62178&r1=62177&r2=62178&view=diff
==============================================================================
--- trunk/printer/tools/test_remote_lpd (original)
+++ trunk/printer/tools/test_remote_lpd Fri Jul 2 17:00:03 2010
@@ -5,15 +5,17 @@
# Remote host $1 and queue $2 are required parameters.
# If no timeout $3 is given it is set to 10 seconds.
#
-# Exits: 0 doesn't seem to have a problem
-# 1 remote host $1 or queue $2 not set
-# 2 the remote host $1 is unreachable (network issue or firewall active?)
-# 3 no connection possible to port 515 on host $1 (no lpd running there or firewall active there?)
-# 4 queue does not accept a print job (queue may not exist or queueing disabled?)
-# 10 ping not executable (no iputils RPM installed?)
-# 11 netcat not executable (no netcat RPM installed?)
-# 12 fuser not executable (no psmisc RPM installed?)
-# 13 mktemp not executable (no mktemp RPM or coreutils RPM installed?)
+# Exits: 0 queue on host accepts print jobs
+# 1 host $1 or queue $2 not set
+# 2 no connection possible to port 515 on host and host does not respond to a 'ping'
+# 3 no connection possible to port 515 on host but host responds to a 'ping'
+# 4 connection possible to port 515 on host but queue does not accept a print job
+# (queue may not exist or queueing disabled?)
+# 5 connection possible to port 515 on host but no free source port to test queue on host
+# 10 no connection possible to port 515 on host and ping not executable (no iputils RPM installed?)
+# 11 give up empty-handed because netcat not executable (no netcat RPM installed?)
+# 12 connection possible to port 515 on host but fuser not executable (no psmisc RPM installed?)
+# 13 connection possible to port 515 on host but mktemp not executable (no mktemp RPM or coreutils RPM installed?)
# up to Suse Linux 10.3 and up to SLE10 /bin/mktemp was in the mktemp RPM
# since Suse Linux 11.0 /bin/mktemp is in the coreutils RPM which is required by YaST
# The programs head, mkfifo, sleep, tr, rm are in the coreutils RPM and therefore assumed to exist.
@@ -33,16 +35,6 @@
# Disable bash file name globbing:
set -f
-# Use the binaries of the operating system (no aliases, functions, /usr/local/):
-export PING=$( type -ap ping | head -n 1 )
-[ -z "$PING" ] && { echo -en "\nping not executable (no iputils RPM installed?)\n" 1>&2 ; exit 10 ; }
-export NETCAT=$( type -ap netcat | head -n 1 )
-[ -z "$NETCAT" ] && { echo -en "\nnetcat not executable (no netcat RPM installed?)\n" 1>&2 ; exit 11 ; }
-export FUSER=$( type -ap fuser | head -n 1 )
-[ -z "$FUSER" ] && { echo -en "\nfuser not executable (no psmisc RPM installed?)\n" 1>&2 ; exit 12 ; }
-export MKTEMP=$( type -ap mktemp | head -n 1 )
-[ -z "$MKTEMP" ] && { echo -en "\nmktemp not executable (no mktemp RPM or coreutils RPM installed?)\n" 1>&2 ; exit 13 ; }
-
MY_NAME=${0##*/}
HOST="$1"
QUEUE="$2"
@@ -50,53 +42,97 @@
TIMEOUT="$3"
[ -z "$TIMEOUT" ] && TIMEOUT=10
-# test whether the remote host is accessible
-$PING -c 1 -w $TIMEOUT $HOST || { echo -en "\nHost $HOST unreachable (network issue or firewall active?)\n" ; exit 2 ; }
-
-# test whether connection is possible to port 515 (lpd) on the remote host
-$NETCAT -w $TIMEOUT -z $HOST 515 || { echo -en "\nNo connection possible to LPD port 515 on host $HOST (no lpd running there or firewall active there?)\n" ; exit 3 ; }
+# Use the binaries of the operating system (no aliases, functions, /usr/local/):
+export PING=$( type -ap ping | head -n 1 )
+export NETCAT=$( type -ap netcat | head -n 1 )
+export FUSER=$( type -ap fuser | head -n 1 )
+export MKTEMP=$( type -ap mktemp | head -n 1 )
-# Find an available local port for connecting
-PORT=$(for I in 721 722 723 724 725 726 727 728 729 730 731
- do
- $FUSER -n tcp $I &>/dev/null || { echo $I ; break ; }
- done)
-
-# Create temporary fifos
-TMP_IN=$( $MKTEMP -u /tmp/$MY_NAME.in.XXXXXX )
-TMP_OUT=$( $MKTEMP -u /tmp/$MY_NAME.out.XXXXXX)
-mkfifo $TMP_IN
-mkfifo $TMP_OUT
+# Test whether netcat is executable:
+if test -z "$NETCAT"
+then # Give up empty-handed when netcat is not executable because only the ping test is meaningless:
+ echo -en "\nGiving up empty-handed because 'netcat' not executable (no 'netcat' RPM installed?)\n" 1>&2
+ exit 11
+fi
+# Test whether connection is possible to port 515 on host:
+if ! $NETCAT -w $TIMEOUT -z $HOST 515
+then # The netcat test failed:
+ echo -en "\nNo connection possible to LPD port 515 on host '$HOST' (no LPD running or firewall active there?)\n\n"
+ # Test whether ping is executable:
+ [ -z "$PING" ] && { echo -en "\n'ping' not executable (no 'iputils' RPM installed?)\n" 1>&2 ; exit 10 ; }
+ # Test whether host is accessible:
+ if $PING -c 1 -w $TIMEOUT $HOST
+ then # The ping test was successful but the netcat test failed:
+ echo -en "\nHost '$HOST' is accessible (responds to a 'ping')\n"
+ exit 3
+ fi
+ # Both the netcat test and the ping test failed:
+ echo -en "\nHost '$HOST' unreachable (network issue or wrong host or firewall active?)\n"
+ exit 2
+fi
+
+# The netcat test succeeded:
+echo -en "\nConnection possible to LPD port 515 on host '$HOST'\n"
+
+# Test whether fuser and mktemp are executable:
+if test -z "$FUSER"
+then echo -en "\nFailed to test if queue '$QUEUE' on host '$HOST' accepts print jobs" 1>&2
+ echo -en "\nbecause 'fuser' not executable (no 'psmisc' RPM installed?)\n" 1>&2
+ exit 12
+fi
+if test -z "$MKTEMP"
+then echo -en "\nFailed to test if queue '$QUEUE' on host '$HOST' accepts print jobs" 1>&2
+ echo -en "\nbecause 'mktemp' not executable (no 'mktemp' RPM or 'coreutils' RPM installed?)\n" 1>&2
+ exit 13
+fi
+
+# Create temporary fifos:
+NETCAT_IN=$( $MKTEMP -u /tmp/$MY_NAME.in.XXXXXX )
+NETCAT_OUT=$( $MKTEMP -u /tmp/$MY_NAME.out.XXXXXX )
+mkfifo $NETCAT_IN
+mkfifo $NETCAT_OUT
# Test the queue:
+echo -en "\nTesting queue '$QUEUE' on host '$HOST':\n"
+
+# Find an available local port for connecting:
+PORT=$( for P in 721 722 723 724 725 726 727 728 729 730 731
+ do $FUSER -n tcp $P &>/dev/null || { echo $P ; break ; }
+ done )
+if test -z "$PORT"
+then echo -en "\nFailed to test if queue '$QUEUE' on host '$HOST' accepts print jobs" 1>&2
+ echo -en "\nbecause there is no LPD source port (721..731) available\n" 1>&2
+ exit 5
+fi
+
# Use source port $PORT and destination port 515 (LPD)
# "\002$QUEUE\n" is a request to receive a new job for $QUEUE
-# The remote lpd sends '\000' if it accepts the request. Then we must
-# send "\001\n" back which is a request to cancel the new job.
+# The remote lpd sends '\000' if it accepts the request.
+# Then we must send "\001\n" back which is a request to cancel the new job.
# After $TIMEOUT netcat would close the connection provided stdin of netcat
# was closed too which would happen if there is any response from the remote port.
# But as there may be no response from the remote port we have additionally
# a time bomb which would kill the netcat process after $TIMEOUT.
-$NETCAT -w $TIMEOUT -p $PORT $HOST 515 <$TMP_IN >$TMP_OUT 2>/dev/null &
+$NETCAT -w $TIMEOUT -p $PORT $HOST 515 <$NETCAT_IN >$NETCAT_OUT 2>/dev/null &
NETCAT_PID=$!
{ sleep ${TIMEOUT}s ; kill $NETCAT_PID &>/dev/null ; } &
RESULT=""
{ echo -en "\002$QUEUE\n" ; \
- RESULT=$( head --bytes=1 <$TMP_OUT | tr '\000' '0' ) ; \
- [ "$RESULT" = "0" ] && echo -en "\001\n" ; } >$TMP_IN
+ RESULT=$( head --bytes=1 <$NETCAT_OUT | tr '\000' '0' ) ; \
+ [ "$RESULT" = "0" ] && echo -en "\001\n" ; } >$NETCAT_IN
-rm $TMP_IN
-rm $TMP_OUT
+rm $NETCAT_IN
+rm $NETCAT_OUT
-[ "$RESULT" = "0" ] && { echo -en "\nQueue $QUEUE on host $HOST accepts print jobs\n" ; exit 0 ; }
+[ "$RESULT" = "0" ] && { echo -en "\nQueue '$QUEUE' on host '$HOST' accepts print jobs\n" ; exit 0 ; }
-echo -en "\nQueue $QUEUE on host $HOST does not accept print jobs (queue may not exist or queueing disabled?)\n"
+echo -en "\nQueue '$QUEUE' on host '$HOST' does not accept print jobs (queue may not exist or queueing disabled?)\n"
# If $QUEUE does not accept jobs, print $QUEUE status in long format.
# "\004$QUEUE\n" is a request to receive $QUEUE status (very long output in case of LPRng).
-echo -en "\nStatus of the queue $QUEUE\n"
+echo -en "\nStatus of the queue '$QUEUE' (possibly empty or not available):\n\n"
echo -en "\004$QUEUE\n" | $NETCAT -w $TIMEOUT -p $PORT $HOST 515
exit 4
Modified: trunk/printer/tools/test_remote_novell
URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/tools/test_remote_novell?rev=62178&r1=62177&r2=62178&view=diff
==============================================================================
--- trunk/printer/tools/test_remote_novell (original)
+++ trunk/printer/tools/test_remote_novell Fri Jul 2 17:00:03 2010
@@ -2,11 +2,12 @@
#
# Test ability to connect to remote IPX Novell server.
#
-# Exits: 0 doesn't seem to have a problem
-# 1 remote host $1 or queue $2 not set
-# 4 queue does not accept a print job (queue may not exist or queueing disabled?)
-# (10=ping,11=netcat,12=fuser,13=mktemp,14=sed,15=lp,16=smbclient: see test_remote_smb)
-# 17 nprint not executable (no ncpfs RPM installed?)
+# Exits: 0 queue on host accepts print jobs
+# 1 host $1 or queue $2 not set
+# 4 queue does not accept a print job but host responds to a 'ping'
+# 10 queue does not accept a print job and ping not executable (no iputils RPM installed?)
+# (11=netcat,12=fuser,13=mktemp,14=sed,15=lp,16=smbclient: see test_remote_smb)
+# 17 give up empty-handed because nprint not executable (no ncpfs RPM installed?)
#
# Johannes Meixner , 2000, 2002, 2007, 2008, 2009, 2010
# Jan Holesovsky , 2000
@@ -23,10 +24,6 @@
# Disable bash file name globbing:
set -f
-# Use the binaries of the operating system (no aliases, functions, /usr/local/):
-export NPRINT=$( type -ap nprint | head -n 1 )
-[ -z "$NPRINT" ] && { echo -en "\nnprint not executable (no ncpfs RPM installed?)\n" 1>&2 ; exit 17 ; }
-
MY_NAME=${0##*/}
HOST=$1
QUEUE=$2
@@ -34,12 +31,41 @@
USER=$3
PASSWORD=$4
TIMEOUT="$5"
-
[ -z "$TIMEOUT" ] && TIMEOUT=10
-# test whether the queue on the server accepts print jobs
-echo -en "\r" | $NPRINT -S "$HOST" -U "$USER" -P "$PASSWORD" -q "$QUEUE" - 2>&1
-[ "$?" = "0" ] && { echo -en "\nQueue $QUEUE on host $HOST accepts print jobs\n" ; exit 0 ; }
-echo -en "\nQueue $QUEUE on host $HOST does not accept print jobs (queue may not exist or queueing disabled?)\n"
-exit 4
+# Use the binaries of the operating system (no aliases, functions, /usr/local/):
+export NPRINT=$( type -ap nprint | head -n 1 )
+
+# Test whether nprint is executable:
+if test -z "$NPRINT"
+then # Give up empty-handed when nprint is not executable because only the ping test is meaningless:
+ echo -en "\nGiving up empty-handed because 'nprint' not executable (no 'ncpfs' RPM installed?)\n" 1>&2
+ exit 17
+fi
+# Test whether the queue on the server accepts print jobs:
+echo -en "\nTesting queue '$QUEUE' on host '$HOST':\n"
+if echo -en "\r" | $NPRINT -S "$HOST" -U "$USER" -P "$PASSWORD" -q "$QUEUE" - 2>&1
+then echo -en "\nQueue '$QUEUE' on host '$HOST' accepts print jobs\n"
+ exit 0
+fi
+
+# The nprint test failed:
+echo -en "\nQueue '$QUEUE' on host '$HOST' does not accept print jobs (queue may not exist or queueing disabled?)\n\n"
+
+# Test whether ping is executable:
+if test -z "$PING"
+then # ping is not executable and the nprint test failed:
+ echo -en "\n'ping' not executable (no 'iputils' RPM installed?)\n" 1>&2
+ exit 10
+fi
+# Test whether host is accessible:
+if $PING -c 1 -w $TIMEOUT $HOST
+then # The ping test was successful but the nprint test failed:
+ echo -en "\nHost '$HOST' is accessible (responds to a 'ping')\n"
+ exit 4
+fi
+
+# Both the nprint test and the ping test failed:
+echo -en "\nHost '$HOST' unreachable (network issue or wrong host or firewall active?)\n"
+exit 2
Modified: trunk/printer/tools/test_remote_smb
URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/tools/test_remote_smb?rev=62178&r1=62177&r2=62178&view=diff
==============================================================================
--- trunk/printer/tools/test_remote_smb (original)
+++ trunk/printer/tools/test_remote_smb Fri Jul 2 17:00:03 2010
@@ -2,13 +2,13 @@
#
# Test ability to connect to remote SMB server.
#
-# Exits: 0 doesn't seem to have a problem
-# 1 remote host $1 or queue $2 not set
-# 2 the remote host $1 is unreachable (network issue or firewall active?)
-# 4 queue does not accept a print job (queue may not exist or queueing disabled?)
-# 10 ping not executable (no iputils RPM installed?)
+# Exits: 0 share on workgroup/host accepts print jobs
+# 1 host $2 or share $3 not set
+# 2 share does not accept a print job and host does not respond to a 'ping'
+# 4 share does not accept a print job but host responds to a 'ping'
+# 10 share does not accept a print job and ping not executable (no iputils RPM installed?)
# (11=netcat,12=fuser,13=mktemp,14=sed,15=lp: see test_remote_ipp)
-# 16 smbclient not executable (no samba-client RPM installed?)
+# 16 give up empty-handed because smbclient not executable (no samba-client RPM installed?)
# The programs head, mkfifo, sleep, tr, rm are in the coreutils RPM and therefore assumed to exist.
#
# Johannes Meixner , 2000, 2002, 2007, 2008, 2009, 2010
@@ -26,31 +26,54 @@
# Disable bash file name globbing:
set -f
-# Use the binaries of the operating system (no aliases, functions, /usr/local/):
-export PING=$( type -ap ping | head -n 1 )
-[ -z "$PING" ] && { echo -en "\nping not executable (no iputils RPM installed?)\n" 1>&2 ; exit 10 ; }
-export SMBCLIENT=$( type -ap smbclient | head -n 1 )
-[ -z "$SMBCLIENT" ] && { echo -en "\nsmbclient not executable (no samba-client RPM installed?)\n" 1>&2 ; exit 16 ; }
-
MY_NAME=${0##*/}
WORKGROUP=$1
HOST=$2
-QUEUE=$3
-[ -z "$HOST" -o -z "$QUEUE" ] && { echo -en "\nUsage:\n$MY_NAME WORKGROUP HOST QUEUE [USER] [PASS] [TIMEOUT]\n" 1>&2 ; exit 1 ; }
+SHARE=$3
+if test -z "$HOST" -o -z "$SHARE"
+then echo -en "\nUsage:\n$MY_NAME WORKGROUP HOST SHARE [USER] [PASSWORD] [TIMEOUT]\n" 1>&2
+ exit 1
+fi
USER=$4
PASSWORD=$5
TIMEOUT="$6"
-
[ -z "$TIMEOUT" ] && TIMEOUT=10
-# test whether the remote host is accessible
-$PING -c 1 -w $TIMEOUT $HOST || { echo -en "\nHost $HOST unreachable (network issue or firewall active?)\n" ; exit 2 ; }
+# Use the binaries of the operating system (no aliases, functions, /usr/local/):
+export PING=$( type -ap ping | head -n 1 )
+export SMBCLIENT=$( type -ap smbclient | head -n 1 )
-# test whether the queue on the server accepts print jobs
-echo -e "\nTesting $QUEUE on $WORKGROUP/$HOST:"
+# Test whether smbclient is executable:
+if test -z "$SMBCLIENT"
+then # Give up empty-handed when smbclient is not executable because only the ping test is meaningless:
+ echo -en "\nGiving up empty-handed because 'smbclient' not executable (no 'samba-client' RPM installed?)\n" 1>&2
+ exit 16
+fi
+# Test whether the SMB share on the server accepts print jobs:
+echo -en "\nTesting share '$SHARE' on '$WORKGROUP/$HOST':\n"
test -z "$PASSWORD" && PASSWORD="-N"
-echo -en "\r" | $SMBCLIENT "//$HOST/$QUEUE" "$PASSWORD" -c "print -" -U "$USER" -W "$WORKGROUP"
-[ "$?" = "0" ] && { echo -en "\nShare $QUEUE on $WORKGROUP/$HOST accepts print jobs\n" ; exit 0 ; }
-echo -en "\nShare $QUEUE on $WORKGROUP/$HOST does not accept print jobs (queue may not exist or queueing disabled?)\n"
-exit 4
+if echo -en "\r" | $SMBCLIENT "//$HOST/$SHARE" "$PASSWORD" -c "print -" -U "$USER" -W "$WORKGROUP"
+then echo -en "\nShare '$SHARE' on '$WORKGROUP/$HOST' accepts print jobs\n"
+ exit 0
+fi
+
+# The smbclient test failed:
+echo -en "\nShare '$SHARE' on '$WORKGROUP/$HOST' does not accept print jobs (share may not exist?)\n\n"
+
+# Test whether ping is executable:
+if test -z "$PING"
+then # ping is not executable and the smbclient test failed:
+ echo -en "\n'ping' not executable (no 'iputils' RPM installed?)\n" 1>&2
+ exit 10
+fi
+# Test whether host is accessible:
+if $PING -c 1 -w $TIMEOUT $HOST
+then # The ping test was successful but the smbclient test failed:
+ echo -en "\nHost '$HOST' is accessible (responds to a 'ping')\n"
+ exit 4
+fi
+
+# Both the smbclient test and the ping test failed:
+echo -en "\nHost '$HOST' unreachable (network issue or wrong host or firewall active?)\n"
+exit 2
Modified: trunk/printer/tools/test_remote_socket
URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/tools/test_remote_socket?rev=62178&r1=62177&r2=62178&view=diff
==============================================================================
--- trunk/printer/tools/test_remote_socket (original)
+++ trunk/printer/tools/test_remote_socket Fri Jul 2 17:00:03 2010
@@ -2,13 +2,13 @@
#
# Test ability to connect to remote direct socket (JetDirect) server.
#
-# Exits: 0 doesn't seem to have a problem
-# 1 remote host $1 not set
-# 2 the remote host $1 is unreachable (network issue or firewall active?)
-# 3 no connection possible to port 9100 or port $2 on host $1 (wrong port or firewall active there?)
-# 4 port 9100 or port $2 on host $1 does not accept data (wrong port or firewall active there?)
-# 10 ping not executable (no iputils RPM installed?)
-# 11 netcat not executable (no netcat RPM installed?)
+# Exits: 0 port on host accepts data
+# 1 host $1 not set
+# 2 no connection possible to port on host and host does not respond to a 'ping'
+# 3 no connection possible to port on host but host responds to a 'ping'
+# 4 connection possible to port on host but does not accept data
+# 10 no connection possible to port on host and ping not executable (no iputils RPM installed?)
+# 11 give up empty-handed because netcat not executable (no netcat RPM installed?)
# The program head is in the coreutils RPM and therefore assumed to exist.
#
# Johannes Meixner 2002, 2007, 2008, 2009, 2010
@@ -25,12 +25,6 @@
# Disable bash file name globbing:
set -f
-# Use the binaries of the operating system (no aliases, functions, /usr/local/):
-export PING=$( type -ap ping | head -n 1 )
-[ -z "$PING" ] && { echo -en "\nping not executable (no iputils RPM installed?)\n" 1>&2 ; exit 10 ; }
-export NETCAT=$( type -ap netcat | head -n 1 )
-[ -z "$NETCAT" ] && { echo -en "\nnetcat not executable (no netcat RPM installed?)\n" 1>&2 ; exit 11 ; }
-
MY_NAME=${0##*/}
HOST="$1"
[ -z "$HOST" ] && { echo -en "\nUsage:\n$MY_NAME HOST [PORT [TIMEOUT]]\n" 1>&2 ; exit 1 ; }
@@ -39,15 +33,45 @@
TIMEOUT="$3"
[ -z "$TIMEOUT" ] && TIMEOUT=10
-# test whether the remote host is accessible
-$PING -c 1 -w $TIMEOUT $HOST || { echo -en "\nHost $HOST unreachable (network issue or firewall active?)\n" ; exit 2 ; }
+# Use the binaries of the operating system (no aliases, functions, /usr/local/):
+export NETCAT=$( type -ap netcat | head -n 1 )
+export PING=$( type -ap ping | head -n 1 )
-# test whether connection is possible to $PORT on the remote host
-$NETCAT -w $TIMEOUT -z $HOST $PORT || { echo -en "\nNo connection possible to port $PORT on host $HOST (wrong port or firewall active there?)\n" ; exit 3 ; }
+# Test whether netcat is executable:
+if test -z "$NETCAT"
+then # Give up empty-handed when netcat is not executable because only the ping test is meaningless:
+ echo -en "\nGiving up empty-handed because 'netcat' not executable (no 'netcat' RPM installed?)\n" 1>&2
+ exit 11
+fi
+# Test whether connection is possible to port on host:
+if $NETCAT -w $TIMEOUT -z $HOST $PORT
+then # Test whether port on host accepts data:
+ if echo -en "\r" | $NETCAT -w $TIMEOUT $HOST $PORT 2>&1
+ then echo -en "\nPort '$PORT' on host '$HOST' accepts data\n"
+ exit 0
+ fi
+ echo -en "\nConnection possible to port '$PORT' on host '$HOST' but does not accept data\n"
+ exit 4
+fi
+
+# The netcat test failed:
+echo -en "\nNo connection possible to port '$PORT' on host '$HOST' (wrong port or firewall active there?)\n\n"
+
+# Test whether ping is executable:
+if test -z "$PING"
+then # ping is not executable and the netcat test failed:
+ echo -en "\n'ping' not executable (no 'iputils' RPM installed?)\n" 1>&2
+ exit 10
+fi
+# Test whether host is accessible:
+if $PING -c 1 -w $TIMEOUT $HOST
+then # The ping test was successful but the netcat test failed:
+ echo -en "\nHost '$HOST' is accessible (responds to a 'ping')\n"
+ exit 3
+fi
+
+# Both the netcat test and the ping test failed:
+echo -en "\nHost '$HOST' unreachable (network issue or wrong host or firewall active?)\n"
+exit 2
-# test whether $PORT on the remote host accepts data
-echo -en "\r" | $NETCAT -w $TIMEOUT $HOST $PORT 2>&1
-[ "$?" = "0" ] && { echo -en "\nPort $PORT on host $HOST accepts data\n" ; exit 0 ; }
-echo -en "\nPort $PORT on host $HOST does not accept data (wrong port or firewall active there?)\n"
-exit 4
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org