Awk and meminfo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk and meminfo
# 1  
Old 08-20-2010
Awk and meminfo

I'm in the process of adding various data to my rrdtool setup, and one of the things i want ot monitor is the meminfo stuff.

I have it running locally very well with the following:
Code:
/usr/bin/rrdupdate /etc/rrdtool/192.168.43.254.mem.rrd --template \
    used:free:buff:cached:swap N:`awk ' \
    /^MemTotal:/    {total=$2*1024}
    /^MemFree:/     {free=$2*1024}
    /^Buffers:/     {buff=$2*1024}
    /^Cached:/      {cached=$2*1024}
    /^SwapTotal:/   {swaptotal=$2*1024}
    /^SwapFree:/    {swapfree=$2*1024}
    END {
        used=total-(free+buff+cached)
        swap=swaptotal-swapfree
        print used ":" free ":" buff ":" cached ":" swap
    }' /proc/meminfo`

But when I try and run an SSH command prior to this, i.e. for a remote server, I get errors. Can someone give me a clue as to what I'm doing wrong?

Code:
/usr/bin/rrdupdate /etc/rrdtool/192.168.43.253.mem.rrd --template \
    used:free:buff:cached:swap N:`ssh 192.168.43.253 "awk ' \
    /^MemTotal:/    {total=$2*1024}
    /^MemFree:/     {free=$2*1024}
    /^Buffers:/     {buff=$2*1024}
    /^Cached:/      {cached=$2*1024}
    /^SwapTotal:/   {swaptotal=$2*1024}
    /^SwapFree:/    {swapfree=$2*1024}
    END {
        used=total-(free+buff+cached)
        swap=swaptotal-swapfree
        print used ":" free ":" buff ":" cached ":" swap
    }' /proc/meminfo"`

Quote:
awk: line 1: syntax error at or near *
awk: line 2: syntax error at or near *
awk: line 3: syntax error at or near *
awk: line 4: syntax error at or near *
awk: line 5: syntax error at or near *


Thanks
James
# 2  
Old 08-20-2010
Save your script in a file and call it on the remote server like the following.
Code:
ssh user@server "bash -s " < script.sh

# 3  
Old 08-20-2010
Thanks for the reply....

I was hoping not to have to put the script of the remote server, but if needs must!

Also, not sure what the "bash -s" was meant for, as it didn't work, but the following has worked:
Code:
ssh user@server /bin/sh /etc/script.sh

Thanks
Nunners
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

MemFree from /proc/meminfo

From the following /proc/meminfo output only ~2GB is free out of total 250GB, but Cached is 194630300 kB. My customer is concerned over the very little memory showing as free. Kindly shed some light if the free memory available in this situation is some thing we need to worry or can we take it as... (2 Replies)
Discussion started by: michaelrozar17
2 Replies

2. Shell Programming and Scripting

awk output yields error: awk:can't open job_name (Autosys)

Good evening, Im newbie at unix specially with awk From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example 1. This is the inputfile: $ more MapaRep.txt ds_extra_nikira_usuarios... (18 Replies)
Discussion started by: alexcol
18 Replies

3. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

4. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

5. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

6. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

7. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

8. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

9. Filesystems, Disks and Memory

Buffer Cache Stats from /proc/meminfo

Hi, I am trying to understand the role of buffer cache in block I/O. I am monitoring /proc/meminfo, my question is does the value of 0 for 'buffers', mean that any subsequent disk read issued by a process, would get the data physically from the disk, and not an allocated buffer for the block? ... (1 Reply)
Discussion started by: jake24
1 Replies

10. Linux

Meminfo

This server is running slowly This is our mail server What is 'cached' in /proc/meminfo ? Can I minimize the usage of cached ? (1 Reply)
Discussion started by: dipanrc
1 Replies
Login or Register to Ask a Question