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

Hylafax on Centos Scripts

© March 2010 Anthony Lawrence

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:



# extract the fax number

$faxnum=~ tr/0-9//cd;
$faxnum=~ s/ //g;
chomp $faxnum;

# extract the vendor name
$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";

# 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:

chdir("/var/spool/hylafax/doneq") or die "Hylafax gone!";
while(<q*>) {
   foreach (@stuff) {
    $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"
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:

if ($s > 25) {
 while ($good[$x]) {
   print I $good[$x++];
if ($s > 25) {
 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.

Got something to add? Send me email.

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

Printer Friendly Version

-> Scripts for Hylafax 6 on Centos 5

Inexpensive and informative Apple related e-books:

Take Control of the Mac Command Line with Terminal, Second Edition

Digital Sharing Crash Course

Take Control of Upgrading to El Capitan

Take Control of High Sierra

Take Control of Parallels Desktop 12

More Articles by © Anthony Lawrence

Printer Friendly Version

Have you tried Searching this site?

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

Printer Friendly Version

I love deadlines. I love the whooshing noise they make as they go by. (Douglas Adams)

Linux posts

Troubleshooting posts

This post tagged:

Fax Software



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode