0

I am using QNX to modify some files and then output some information abou those files. the process is similar to the following: find certain files in a directory if the names are less than a value perfomr dd command output file - info - staus

find $DIR -type n \( ! -iname "*sub*" \) -exec basename {} |
while read fname
do
    if [ $(printf '%d\n' 0x$fname) -lt 31 ] #if file is < 31
    then 
        dd bs=1 skip=67 count=1 if=/path/$fname/random of=/tmp/$fname
        echo -n " "$fname"      "  #output file name
        TEMP=$(</tmp/$fname)       #temporary file is in 
        hd -A x /tmp/$fname | gawk '{printf $2}'

        if [ $fname == 06 ]; then
            COM="Testing on 06" # this is temporary
        elif [ $fname == 08 ]; then
            case "?? hex value of $2 ?? in
                00) COM="DOWN" ;; #again, not sure what works
                0x01) COM="UP" ;;
                02) COM="Pass Through Mode" ;;
                *) COM="ERROR" ;;
            esac
        else 
            if [[ $STATE = 0x00 ]]; then #doesn't work either
                COM="DOWN"
            elif [ "(hd -A x /tmp/$fname | gawk '{printf $2}')" == 0x01 ]; then
                COM="UP"
            else
                COM="ERROR $STATE "
            fi
        fi

        echo "        " $COM



    fi
done

I need a comparison to be able work between the hex value of the dd output and a hex digit, or even integer comparisons.

2 Answers2

0

You can store results, sent to stdout from particular command in variable by enclosing it in ` quotes:

linecount = `cat text.txt|wc -l`
David Jashi
  • 4,490
  • 1
  • 21
  • 26
0

Use backticks to capture the output of a unix command into a unix variable, ie

   t=`/bin/date`
   echo the time is $t

You can probably do something like this

   firstByte = `dd bs=1 skip=67 count=1 if=/path/$fname/random of=- | hd -A x`

although you will need some additional arguments to hd to suppress the address info (I assume that is what you are trying to do with the gawk step. I don't know hd well enough -- read the man page.

Mark Lakata
  • 19,989
  • 5
  • 106
  • 123