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