Find the answer to your Linux question:
Results 1 to 5 of 5
I have a basic awk script that can read a file named 'server_info' and output to the screen which fax lines are not working. Now I want to make the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    7

    Can I use Bash within an awk script


    I have a basic awk script that can read a file named 'server_info' and output to the screen which fax lines are not working. Now I want to make the script execute commands instead of printing to the screen but I am having trouble... This is better explained by my code below:

    test.sh
    Code:
    #!/usr/bin/awk -f
    #
    #The name of this script is test.sh
    #The script is created on April 14, 2011.
    #This script is last modified on April 14, 2011.
    #The purpose of this script is to correct issues with Rephms1 fax modems
    # This icludes checking status, and applying know corrections to the issue
    # at hand
    
    
    BEGIN {
      print "--- checking server_info"
      failed=0
      }
    {
      if (NR >4) {
        if ($4 == "MODEM") {
          if($5 == "OK:") {
    #DO NOTHING
          }
        }
        else if($4 == "SENDING") {
    #DO NOTHING
        }
        else {
    #EXECUTE KNOWN FIX BELOW INSTEAD OF PRINTING TO SCREEN
          print "failed MODEM:\t"$1" "$4" "$5" "$6" "$7" "$8
          failed=failed+1
    
        }
      }
    }
    END {
      print "---------------------------------------"
      printf("\ttotal number of failed Modems:\t%d\n",failed)
    }
    The above code is awk'ing a file named 'server_info' which is displayed below:

    *EXAMPLE* server_info
    Code:
    Fax server info, last update Thu Apr 14 10:32:17 2011
    
    Line         Model         Usage      Status
    ----         -----         -----      ------
    /dev/ttyACM0 Multitech     SEND/REC   SENDING pid=22979  C_1302553930_0
    /dev/ttyACM1 Multitech     SEND/REC   MODEM OK: IDLE
    /dev/ttyACM2 Multitech     SEND/REC   DOWN: NO PERMISSION TO ACCESS
    Within the ELSE statement in test.sh I would like to run the command:

    Code:
    chmod 666 $1
    The $1 would be the device name awked from server_info. Is there a way to run commands like this within my script or would I have to re-create the script as a bash script invoking awk?

  2. #2
    Just Joined!
    Join Date
    Apr 2011
    Posts
    7
    I'm still interested to know if I can call other commands from within an awk script...

    BUT while I was waiting I gave a shot at bash and I think I may have created a script that will perform exactly what I need just differently than the above test.sh

    rephms1_script.sh
    Code:
    #!/bin/bash
    # rephms1_script.sh
    #
    #The script is created on April 14, 2011.
    #This script is last modified on April 14, 2011.
    #The purpose of this script is to correct issues with fax modems
    # This icludes checking status, and applying know corrections to the issue
    # at hand
    
    
    LINE_NUMBERS=$(awk 'END{print NR}' ~fax/server_info)
    
    check_modems() {
      MODEM[1]="$(awk -v ln_n="$1" 'NR==ln_n {print $1}' ~fax/server_info)"
      MODEM[4]="$(awk -v ln_n="$1" 'NR==ln_n {print $4}' ~fax/server_info)"
      MODEM[5]="$(awk -v ln_n="$1" 'NR==ln_n {print $5}' ~fax/server_info)"
      MODEM[0]="$(awk -v ln_n="$1" 'NR==ln_n {print $4" "$5" "$6" "$7" "$8}' ~fax/server_info)"
    
      if [ ${MODEM[4]} == "SENDING" ]
      then
    #DO NOTHING
      elif [ ${MODEM[4]} == "MODEM" ]
      then
        if [ ${MODEM[5]} == "OK:" ]
        then
    #DO NOTHING
        fi
      else
          if [ "${MODEM[0]}" == "DOWN: NO SUCH DEVICE " ]
          then
              #COMMANDS GO HERE
              #COMMANDS GO HERE
          elif [ "${MODEM[0]}" == "DOWN: NO PERMISSION TO ACCESS" ]
          then
              chmod 666 ${MODEM[1]}
          elif [ "${MODEM[0]}" == "DOWN: NO RESPONSE FROM MODEM" ]
          then
              #COMMANDS GO HERE
              #COMMANDS GO HERE
          fi
      fi
    }
    
    
    for (( c=5; c<=$LINE_NUMBERS; c++))
    do
    Do you approve of this new method? I've never written scripts before so these are my first attempts.

  3. #3
    TWG
    TWG is offline
    Just Joined!
    Join Date
    Dec 2011
    Posts
    2
    Hi Sephlaire,

    We are using 3 Multi Tech Modems (MT9234ZBA-USB-CDC) in our environment and some times ttyACM0 goes down some times ttyACM2 goes down, to bring them back each time we have to un-plug the modem and plug them back in, do you have any idea what causing the modems to go down and a permanent fix for this problem. Right now they look like this:

    Line Model Usage Status
    ---- ----- ----- ------
    /dev/ttyACM0 Multitech SEND_ONLY DOWN: NO RESPONSE FROM MODEM
    /dev/ttyACM1 Multitech SEND_ONLY SENDING pid=2546 C_1323700670_0
    /dev/ttyACM2 Multitech SEND_ONLY DOWN: NO RESPONSE FROM MODEM

    OS: RHEL 5.5 server
    kernel version: 2.6.18-194.32.1.el5

    Any suggestions are highly appreciated. Thanks in advance.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Apr 2011
    Posts
    7
    Unfortunately we have not found a permanent fix yet. We still have to walk over to our to the modems ever time they stop working to powercycle them.

    We also have no idea whats causing them to fail. Performance has improved since a major software upgrade to our Clinical Suite which controls what is being sent to the modems but beyond that we haven't got much farther.

    The only solution that has been offered to us from the software vendor is to move towards a new server with build in PCI modems as opposed to our current setup. (3 USB modems plugged into a USB Hub.)

  6. #5
    TWG
    TWG is offline
    Just Joined!
    Join Date
    Dec 2011
    Posts
    2

    Fax Modems Issue

    Hi Sephlaire,

    Thank you so much for your response. We also used powered external USB hub as of our IsoFax vendor suggested and it worked fine for 4 days and then modems got locked-up they showed they were sending faxes but they weren't we found out this by looking at the last update time by (view_server_info). After couple hours the server got hang-up so we had to reboot the server.

    Our IsoFax vendor also said these modems (MT9234ZBA-USB-CDC) are new and they have limited experience on them, instead he suggested us to purchase the older model (MT5634ZBA-USB ) and he adds "This modem has been proven in over 100 IsoFax sites", but he did not promise this is the perfect one and also other option to go for internal modems that sits on motherboard of the server (as you mentioned PCI modems). I found out that these modems use cdc-acm driver which is built into kernel and I think this driver may not work properly when multiple modems connected. We have the same modem in other location and they don't have any issues (they only have one modem), but in our location we had the same issue when we had one modem. I am doing some reserach and some test, if I come-up with some thing I let you know. Thanks for your time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •