Confused on how to script item


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Confused on how to script item
# 1  
Old 04-09-2014
Confused on how to script item

I am working on a script that will parse the /proc/meminfo file and return values. I have been able to pull the MemTotal and MemFree from that file but have stumbled on the next thing I want to do - calculate memory used via subtracting MemFree from MemTotal.

Would I do something like -
Code:
memfree=$(more /proc/meminfo | grep MemFree
memtotal=$(more /proc/meminfo| grep MemTotal
Let usedmem=$memtotal-$memfree

echo "Total Memory: $memtotal  Free Memory: $memfree  Memory in use: $usedmem

that? If not, what would be the best method to do this calculation?
# 2  
Old 04-09-2014
Code:
usedmem=$((memtotal - memfree))

# 3  
Old 04-09-2014
Remember that cached counts as free, too.
# 4  
Old 04-09-2014
Thank you! I added that to my script and it works.
# 5  
Old 04-09-2014
I'm not sure above will work as the values might have a header with them. Try
Code:
grep  ^Mem /proc/meminfo | { read X MEMTOT R;read X MEMFRE R; echo $MEMTOT $MEMFRE $((MEMTOT-MEMFRE)); }

# 6  
Old 04-09-2014
My script is complete and does exactly what I want it to do. Thank you once more!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to process a list of items and uncomment lines with that item in a second file

Hello, I have a src code file where I need to uncomment many lines. The lines I need to uncomment look like, C CALL l_r(DESNAME,DESOUT, 'Gmax', ESH(10), NO_APP, JJ) The comment is the "C" in the first column. This needs to be deleted so that there are 6 spaces preceding "CALL".... (7 Replies)
Discussion started by: LMHmedchem
7 Replies

2. UNIX for Beginners Questions & Answers

Why this script is not working as 'expected' when doing ssh with while read ... really confused?

Hi, I have a script below that is running ssh <host> <command> on some servers. Below is more or less the script. I have to modify it somehow to get rid of the 'confidential' hostnames check_log.bash #!/bin/bash # myPID=$$ parse_log () { sub="parse_log" host=${1} ... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

Bash shell script undefined array item value question

Hello, I'm new here. I test these expressions's value in my script : (in centOS 6 ) #!/bin/bash array='something' echo "############" echo ${array} echo ${array} echo ${array} echo "############" The output result is : ################# something something #################... (5 Replies)
Discussion started by: lingjing
5 Replies

4. Shell Programming and Scripting

Create mysql database with bash script - confused

Hi, i have the following: db="create database xxx;GRANT ALL PRIVILEGES ON xxx.* TO user@localhost IDENTIFIED BY 'password';FLUSH PRIVILEGES;quit;" mysql -u root -p$mysql_pass -e "$db" I don't understand why this is failing, it works fine when run from cmd but when is run in a bash script,... (1 Reply)
Discussion started by: ktm
1 Replies

5. Shell Programming and Scripting

How do I check using shell-script if an item is available in a database?

Input for the program is a text file consisting of n no. of items. I want search each item in a database and the existing parts should go to FOUND folder and the others should go to NOTFOUND folder. Pls help me in this. Thank u. (1 Reply)
Discussion started by: smarty86
1 Replies

6. UNIX for Dummies Questions & Answers

replace item..

Hello, I have the following basic script which is remove the fielld. How can I replace another value in the field? Thx!! for file in `cat $listn.txt` do get_file -q $file grep -v '<customer-id>13000</customer-id>' $file > $file.grep done echo All processed file done!! input file:... (2 Replies)
Discussion started by: happyv
2 Replies

7. Shell Programming and Scripting

find an available item in array

Dear all, I'm have a sorted array like this: 177 220 1001 2000 2001 2003 2005 notice that 2002 and 2004 are NOT in array. Then user input a number INPUT, our script should return OUTPUT value like this: if INPUT is not in array => OUTPUT=INPUT if INPUT is in array => OUTPUT is the... (4 Replies)
Discussion started by: fongthai
4 Replies

8. Shell Programming and Scripting

change some record item

Hi all, I have a file with over 10,000 line, but I would like to update/add some code number (such as 062 below) into the line with <phone number> below: 11111<name> john matin <name> 12345<phone number> 123456 <phone number> 34556 <address> 1234 lucky road <address> 11111<name> john... (7 Replies)
Discussion started by: happyv
7 Replies

9. Shell Programming and Scripting

Skip item by using substring

I have a file contents like this.... item1 item2 #item3 item4 #item5 item6 .... I have a KSH script to read this file into an array. I have a for loop which will read each item... I want to be able to skip those item start with # sign as first character in a if condiction inside the... (2 Replies)
Discussion started by: rwunwla
2 Replies
Login or Register to Ask a Question