APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS














(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



Print to FAX with custom tags






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").




Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar


LOD Communications, Inc.

cartoon
Looking for Mac OS X Help?
OS X PDF e-books
Inexpensive, instant download


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. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server




pavatar.jpg
More:
       - Printing
       - Administration




Related Posts

Using System V interface scripts with CUPS printing

Redhat /etc/alternatives

Cups print to file

Sco/Linux transition guide

CUPS and Netgear PS110

Cups bought by Apple

IPP



Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress