Saturday, January 1, 2011

Hylafax on Centos Scripts

Linux,OSR5

2010/03/22

I finally did get back to the SCO to CentOS conversion I mentioned back in November at Hylafax 6 on Centos 5. This all took so long because the application (a point-of-sale system) is critically important to the customer and every detail had to be tested and retested. That testing sometimes involved disrupting normal operations, so it was hard to schedule and we always had limited time. Eventually it all came together and they now are running on Centos.

Aside from transferring user accounts, printers, and so on, my work was just to convert Vsifax scripts to Hylafax. Those scripts were called by the application program to do such things as fax a Purchase Order to a vendor. The programming is simple enough: you find and extract the fax number and pass that all off to Hylafax. For purposes of logging and error control, we also wanted to identify the vendor name, which required adding that name to the logs that Hylafax keeps or maintaining a separate index of names to faxes queued. At first I thought I might have to do the latter - Hylafax does allow you to add an "identification" tag to faxes, but none of its tools (like "faxstat") show that tag. However, the tag does appear in log files, so I could get what I needed.

Let's take a look at some of the basic scripts involved here.

The first task is to extract a fax number and vendor name. That's easy enough:

 #!/usr/bin/perl $err=0; $login=$ENV{LOGNAME};  @stuff=<>;  # extract the fax number $faxnum=substr($faxline,9,14);  $faxnum=~ tr/0-9//cd; $faxnum=~ s/ //g; chomp $faxnum;  # extract the vendor name $tg1=substr($stuff[7],10,25); $tg1=~s/^\s+//; $tg1=~s/\s+$//; $tg1=~s/ /_/g;  if ($err or not $faxnum) { # if there is no fax number, print the PO for hand faxing or investigation   open(O,"|/usr/bin/lp -dRECEIVING");   print O "Fax request from $login problem\n";   print O "No faxnumber $faxline \n" if not $faxnum;   print O "===============\n";   foreach(@stuff) {      print O $_;   } close O;  exit 0; }  # send fax and add $tg1 tag to log $cmd="sendfax -i $tg1 -n -d \"customer\@$faxnum\" $file"; system($cmd);  # reset fax modem status system("faxmodem ttyS0"); exit 0; 

By the way, by default, Hylafax converts text and adds healthy margins at the top and bottom of the fax. These pushed our PO to two pages when it didn't really need to be. To take those out, I modified /usr/local/lib/fax/typerules to adjust the arguments sent to "texfmt" (the program that converts text to a tiff to fax):

 0       ascii           x               ps      %F/textfmt -B -f Courier-Bold\                                  -Ml=0.4in,t=0.1in,b=0.1in -p 11 -s %s >%o <%i  

You could do the same thing by adding to your config file in /var/spool/hylafax/etc/:

 PageMargins : l=0.40in,r=0.40in,t=0.1in,b=0.1in 

You can also adjust the default font size and style,

Now we need something to let them see the status of faxes. As I noted above, the default "faxstat" program doesn't pick up the tag they want, so I wrote a cron script that regularly checks the Hylafax "doneq" (completed faxes, successful or not) and rewrites data to other files:

 #!/usr/bin/perl $notify="faxerrs@thiscustomer.com"; chdir("/var/spool/hylafax/doneq") or die "Hylafax gone!"; while(<q*>) {    open(I,$_);    @stuff=<I>;    foreach (@stuff) {       chomp;     $status=$_ if /^status:/;     $number=$_ if /^number/;     $jobtag=$_ if /^jobtag/;     $mailaddrees=$_ if /^mailaddrees/;    }    $status=~ s/^status: *//;    $number=~ s/^number: *//;    $jobtag=~ s/^jobtag: *//;    $mailaddress=~ s/^mailaddress: *//;    push @line,"$_ $number $mailaddress $jobtag $status\n";    if ($status) {     # not sent     open(O,"|/usr/local/bin/email -subject 'Fax failure '  $notify"     print O "$_ $number $mailaddress $jobtag $status\n";     close O;     open(BAD, ">>/tmp/badfax");     print BAD "$_ $number $mailaddress $jobtag $status\n";     close BAD;    }   if (not $status) {       open(GOOD, ">>/tmp/goodfax");       print GOOD "$_ $number $mailaddress $jobtag $status\n";       close GOOD;   } # remove from "doneq"   unlink("$_"); } exit 0;  

Their application has menu choices to look at either the successful or failed faxes. Those just do something like:

 tac /tmp/badfax | less 

("tac" works like "cat" but reverses the file so the latest addition will be at the top)

Another cron job cleans out these files as necessary:

  #!/usr/bin/perl open(I,"/tmp/goodfax"); @good=<I>; $s=@good; if ($s > 25) {  $x=20;  open(I,">/tmp/goodfax");  while ($good[$x]) {    print I $good[$x++];  } } open(I,"/tmp/badfax"); @bad=<I>; $s=@bad; if ($s > 25) {  $x=20;  open(I,">/tmp/badfax");  while ($bad[$x]) {    print I $bad[$x++];  } } 

Notice that I never clean out the file completely; it's always the latest 20 lines that are left there.

Comments: Click Here.

Want to showcase your product to our audience? Check our advertising options.



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. If you have any question, please do feel free to contact me.


Source: http://feedproxy.google.com/~r/aplawrence/DOLL/~3/06czJ1NqPQM/hylafax-scripts.html

colt brennan accident cell phone eva longoria ipad iphone

No comments:

Post a Comment