Re: smb printer trouble
Thanks, and no-thanks at the same time ;) The 'push back' will help (so I can avoid the temp file) and I will put that in. However, my filter is doing just fine on postscript files (and since it is a postscript pinter I don't have to put it through gs). The problem is with _non_ postscript files where the first line contains the '\' char at the end of the line, the read procedure sees that as "chomp the newline, and keep going as if the line never ended" I need to see if there is a way to avoid that behavior so my filter can print all files without messing them up ;) Thanks for the 'push back' help though! James. - Original Message - From: [EMAIL PROTECTED] To: "James Halstead" [EMAIL PROTECTED] Sent: Thursday, May 18, 2000 7:44 AM Subject: Re: smb printer trouble Actually, if there is a way that I can read only the first two chars from the standard input that would solve the problem for nearly all the cases. I only need the first two chars to do my test, then I can leave the rest up to cat. It would be even better if sombody could tell me a way to push chars back on to the stdin stream that way I can completly avoid making a temporary file. I don't know if this will help; I filched it from a simple printer filter example that is somewhere in the distribution. It's a shell script that checks the first few characters (on stdin) to see if it's getting a PostScript file or something else. #!/bin/sh Esc="\033" printf "${Esc}E" || { logger "lp filter: error resetting printer" printf "lp filter: error resetting printer\n" 2 exit 0 # delete job from queue } read First_line Magic=$(expr "$First_line" : '\(\)') case $Magic in %!PS) /usr/local/bin/gs -dSAFER -dNOPAUSE -q -sDEVICE=cdj550 \ -sPAPERSIZE=a4 -sOutputFile=- - exit 0 ;; ~lpx) Found_end=0 Type=nil while [ ${Found_end} -eq 0 ] do read Keyword Value case ${Keyword} in type)Type=${Value};; ... and so on. If the first 4 characters ('$Magic') are '%!PS', everything from stdin is slurped up by /usr/local/bin/gs, which interprets it to stdout and then exits. You'll notice that the first line of stdin does not go to gs (which doesn't need it). If it had been necessary to 'push back' that first line, it would have been easy, e.g.: (echo $First_line; cat) | /usr/local/bin/gs I hope this has been of some help... -- Tim Jackson To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
RE: smb printer trouble
Perhaps there are some invisible spaces after some of the backslashes? Kees Jan == You are only young once, but you can stay immature all your life -Original Message- From: Charlie Root [mailto:[EMAIL PROTECTED]] Sent: dinsdag 16 mei 2000 20:39 To: [EMAIL PROTECTED] Subject: smb printer trouble I wrote a simple filter to print to an nt print queue through the smbclinet. It tests to see if the file is postscript or text, and if it is text it sends a control code to tell the printer to do the lf-crlf conversion. My problem is that the '\' escapes in the first line get clobbered. for example, if I print this printcap: begin printcap lp:\ :sh:\ :lp=/dev/lpt0:\ :sd=/var/spool/output/lpd/lp:\ :lf=/var/log/lpd/lpd.log: lplaser:\ :sh:\ :lp=/dev/null:\ :if=/root/filters/smb-filter:\ :sd=/var/spool/output/lpd/lplaser:\ :lf=/var/log/lpd/lpd.log: end printap the entire entry for "lp" will be on one line, but the "lplaser" entry will print out like it is supposed to. I know why it is doing it, however I don't know how to fix it. Any help will be appreciated (script is below). Thanks, James begin smb-filter #!/bin/sh # Input filter to print to a NT print queue, requires smbclient. # # Author: James Halstead, e-mail: [EMAIL PROTECTED] # # Read stdin to a temp, make sure to determine the print type, then use # smbclient to print to the nt queue. SERVER=SERVER NAME PRINTER=cwPRINTER NAME TEMP=/tmp/smbprint TEMP=`mktemp -q $TEMP.XX` read firstline first_two=`expr "$firstline" : '\(..\)'` if [ "$first_two" != "%!" ]; then printf "\033k3G" $TEMP fi #lets see, copy the firstline to temp, cat the rest to the temp, # make one ugly command to print the file to the smb printer then # rm the temp file. echo "$firstline" $TEMP cat $TEMP \ /usr/local/bin/smbclient $SERVER\\$PRINTER -UGUEST -N\ -c"print $TEMP" \ rm -f $TEMP /dev/null exit 0 exit 1 end smb-filter To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: smb printer trouble
I know it is happening because of the ``read firstline'' command. It is using the standard shell way of continuing a line using the '\' char and applying that to the input. That explains why only the first line is effected. Actually, if there is a way that I can read only the first two chars from the standard input that would solve the problem for nearly all the cases. I only need the first two chars to do my test, then I can leave the rest up to cat. It would be even better if sombody could tell me a way to push chars back on to the stdin stream that way I can completly avoid making a temporary file. Thanks, James ([EMAIL PROTECTED]) - Original Message - From: "Koster, K.J." [EMAIL PROTECTED] To: "'Charlie Root'" [EMAIL PROTECTED] Cc: "'FreeBSD Hackers mailing list'" [EMAIL PROTECTED] Sent: Wednesday, May 17, 2000 4:40 AM Subject: RE: smb printer trouble Perhaps there are some invisible spaces after some of the backslashes? Kees Jan == You are only young once, but you can stay immature all your life -Original Message- From: Charlie Root [mailto:[EMAIL PROTECTED]] Sent: dinsdag 16 mei 2000 20:39 To: [EMAIL PROTECTED] Subject: smb printer trouble begin smb-filter #!/bin/sh # Input filter to print to a NT print queue, requires smbclient. # # Author: James Halstead, e-mail: [EMAIL PROTECTED] # # Read stdin to a temp, make sure to determine the print type, then use # smbclient to print to the nt queue. SERVER=SERVER NAME PRINTER=cwPRINTER NAME TEMP=/tmp/smbprint TEMP=`mktemp -q $TEMP.XX` read firstline first_two=`expr "$firstline" : '\(..\)'` if [ "$first_two" != "%!" ]; then printf "\033k3G" $TEMP fi #lets see, copy the firstline to temp, cat the rest to the temp, # make one ugly command to print the file to the smb printer then # rm the temp file. echo "$firstline" $TEMP cat $TEMP \ /usr/local/bin/smbclient $SERVER\\$PRINTER -UGUEST -N\ -c"print $TEMP" \ rm -f $TEMP /dev/null exit 0 exit 1 end smb-filter To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message