PDA

View Full Version : Bash script vnstat



linuxrockz
June 16th, 2009, 09:19 AM
Hi all :)

Here is my bash script. I want it to return the current percentage of my net usage (download) so that I can use the value as execbar in conky. (My monthly limit being 1024MiB).


#!/bin/bash
# Read internet usage from vnstat and store value of download in file.txt
vnstat -m | grep "`date +"%b '%y"`" | awk '{print $3}' > file.txt
# Store the value in file.txt as a variable usage
usage= `cat file.txt`
# Calculate the usage percentage with two decimal points and store the value in file1.txt
echo "scale=2; ($usage/1024)*100" | bc > file1.txt

When I execute it i get the following error



./bashcalc.sh: line 5: 962.57: command not found
(standard_in) 1: syntax error


By the way this is my first bash script and I am no way a programmer, I am just an end user. Frankly speaking I know nothing of programming. :(

Any help would be appreciated.

ghostdog74
June 16th, 2009, 09:22 AM
put set -x in your script and run it again

kpkeerthi
June 16th, 2009, 09:57 AM
It could be the space after the = in line#5

linuxrockz
June 16th, 2009, 10:08 AM
Thanks a lot kpkeerthi the bug was the space :biggrin: removing it solved the problem.
And thanks to you too ghostdog74; i learnt a new thing "set -x" :D