APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

VSI-FAX is a popular commercial fax application. Although it can be used for desktop faxing and for inbound faxes, the most common use is probably automated faxing of documents printed by some application.

A "printer" that faxes isn't hard. Here's a model script for Sys V printers:



#!/usr/bin/perl
# ignore most arguments
$err=0;
$login=$ARGV[1];
$file=$ARGV[5];
open(I,$file) or $err=$!;
@stuff=<I>;close I;
$x=0;
####
#  this is just for debugging 
open(O,">/tmp/lastfax");
foreach(@stuff) {
   print O "$x :$_";
   $x++;
}
close O;
#### 
# The fax number is on the 12th line of the form
$faxline=$stuff[11];
$faxnum=substr($faxline,9,14);
$faxnum=~ tr/0-9//cd;
chomp $faxnum;
$faxnum=~ s/^  *//;
$faxnum=~ s/  *$//;
#  We also pick up a custom tag - the vendor name
$tg1=substr($stuff[7],10,25);
$tg1=~s/^\s+//;
$tg1=~s/\s+$//;
$tg1=~s/ /_/g;
####
# if no fax number print a message to a different printer
if ($err or not $faxnum) {
  open(O,"|/usr/bin/lp -dRECEIVING");
  open(OO,">>/tmp/faxerr");
  print O "Fax request from $login problem\n";
  print O "No faxnumber $faxline \n" if not $faxnum;
  print OO "Fax request from $login problem\n";
  print OO "No faxnumber $faxline \n" if not $faxnum;
  print O "===============\n";
 foreach(@stuff) {
   print O $_;
   print OO $_;
  }
close O;
close OO;
exit 0;
}
####

$cmd="/usr/vsifax/bin/vfx -t tg1=$tg1 -n $faxnum $file";
####
# just for debugging again
open(O,">>/tmp/faxsent");
print O "POFAX $login $cmd\n";
close O;
####
# spools the fax to vsifax
system($cmd);
exit 0;
 

Notice the line that handles "tg1". VSI-FAX has four custom tags that you can use for any purpose. These won't be part of the outgoing fax, but we can access them in vfxolog. We'll see that shortly. First, let's see how we'd use this script.

For System V spoolers, you'd put the script in the lp model directory. For example, that's /usr/spool/lp/model on SCO. I called it POFAX, and created my fax printer as follows:

/usr/lib/lpadmin -p POFAX -v /dev/null -m POFAX
/usr/lib/accept POFAX
enable POFAX
 

For CUPS, I might use the socket idea presented at CUPS (Common Unix Printing System) print to file - the hard way!. I like that better than messing with configuration files. It's also fairly portable - if the spooler system can go to a network port, you can do it that way.

To see the tags, you need to tell vfxolog what you want to see. I do that with this "vflog" script:


#!/usr/bin/perl
$cmd="/usr/vsifax/bin/vfxolog -f \"seq,sbt,npg,nps,tfn,ars,rrs,att,tg1\"";
@stuff=`$cmd`;
$hdr="Req-id  -Submitted-     npg nps  Phone number     Attmpt Result att  Vendor\n";
print $hdr;
$cnt=0;
foreach ( @stuff) {
  chomp;
  $cnt++;
  s/"//g;
  @line=split /,/;
  $tm=$line[1];
  $line[1]=substr($tm,0,4) . "/" . substr($tm,4,2) . "/" . substr($tm,6,2);
  $line[1] .= " " . substr($tm,8,2) . ":" . substr($tm,10,2);
  $tm=$line[4];
  $line[4]= substr($tm,0,3) . " " . substr($tm,3,3) . "-" . substr($tm,6);
  $save="$line[0]   $line[1]   $line[2]   $line[3] $line[4]     $line[5]  $line[6] $line[7] $line[8]";
  print "$save\n";
  if ($cnt == 10) {
    print "More... ";
    $m=<>;
    exit 0 if $m =~ /[qQ]/;
    print $hdr;
    $cnt %= 10;
  }
}
 

You could make this much neater; I didn't make the extra effort to align fields (that's easily done with "printf").



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Print to FAX with custom tags




Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





It's hard to study much history and not dislike religion - (Tony Lawrence)

What happens then? Is there a ticker tape parade and heartfelt thanks from the computer it has reached? No, my friends, there is not. The poor packet is immediately gutted, stripped of its protective layers and tossed into the hungry maw of whatever application (mail, a webserver, whatever) it belongs to. (Tony Lawrence)












This post tagged: