Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am attempting to pull RX packets, CPU vendor and model along with CPU MHz.

Here is my script:

#!/bin/bash
#systemstat

case $1="-r"
COUNT='ifconfig eth0 | grep 'RX packets:' | cut -d: -f2 | awk '{print $1}''
DATE='date +"%H:%M:%S"' echo "Time" $'\t' $'\t' "Total Packets eth0" echo $DATE $'\t' $'\t'$COUNT ;; "-c"
VENDOR='cat /proc/cpuinfo | grep 'vendor_id' | cut -d: -f2 | awk '{print $1}''
MODEL='cat /proc/cpuinfo |grep 'model name' | cut -d: -f2' CPU='more /proc/cpuinfo | grep 'cpu MHz' | cut -d:$

*) echo

;; esac

I am getting the following error:

./systemstat: line 6: syntax error near unexpected token `COUNT='ifconfig eth0 | grep 'RX'
./systemstat: line 6: `COUNT='ifconfig eth0 | grep 'RX packets:' | cut -d: -f2 | awk '{print $1}'' '

Can anyone assist?

Thank you!

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Sincerely, your script is a mess. Before to start with bash scripting, you should read first something like: Bash Guide for Beginners.

Now, your script should look like:

#!/bin/bash
#systemstat

case $1 in
"-r")
    COUNT=`ifconfig eth0 | grep 'RX packets:' | cut -d: -f2 | awk '{print $1}'`
    DATE=`date +"%H:%M:%S"`
    echo -e "Time\t\tTotal Packets eth0" 
    echo -e "$DATE\t\t$COUNT"
    ;; 
"-c")
    VENDOR=`cat /proc/cpuinfo | grep 'vendor_id' | cut -d: -f2 | awk 'NR==1'`
    MODEL=`cat /proc/cpuinfo | grep 'model name' | cut -d: -f2 | awk 'NR==1'` 
    MHZ=`more /proc/cpuinfo | grep 'cpu MHz' | cut -d: -f2 | awk 'NR==1'`
    echo -e "CPU Model:\n $MODEL" 
    echo -e "Vendor:\n $VENDOR" 
    echo -e "MHZ:\n $MHZ" 
    ;;

*) 
    echo -e "Usage: `basename $0` OPTION\n\tOPTIONS:\n\t\t-r -> some explanation\n\t\t-c -> some explanation"
    ;; 
esac

See also: Using case statements.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.