SSH script. (Assign $var to free cmd) ???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SSH script. (Assign $var to free cmd) ???
# 1  
Old 11-27-2009
Question SSH script. (Assign $var to free cmd) ???

Running: GNU/Linux, 2.6.22.9-61.fc6 (hope that's the right info needed)

I am trying give the amount of RAM and the % used. I am using free command.
I am having some problems with this command

code:
1)
Code:
T = `free | grep Mem | awk '{print $2}'`
      F = `free | grep Mem | awk '{print $4}'`
       echo "Amount of RAM(%): {$F / $T * 100}"

I need some help please, I know this is not perfect yet but a push in the right direction would be a great help. When I try this I get this error

error:
Code:
./hardutilinfo: line 10: T: command not found
./hardutilinfo: line 11: F: command not found
Amount of RAM(%): { /  * 100}

Thanks in advance,
Jade x

Last edited by pludi; 11-27-2009 at 07:57 PM.. Reason: code tags, please...
# 2  
Old 11-27-2009
Error 1: There must not be a whitespace between the variable name, the equal sign, and the value.
Error 2: Using curly brackets does not tell the shell to do an arithmetic evaluation

Improvement idea: Run free only once, and calculate the percentage in one awk statement.
# 3  
Old 11-27-2009
what pludi meant is..
Code:
free|awk '/Mem/{print "Amount of RAM(%): " (($4 / $2) * 100)}'

# 4  
Old 11-28-2009
Thankyou

Thankyou, This was a great help. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute command using ssh server 'cmd'

Hi The command below does not work as it require to take command in the breakers But If I do so the variable values get lost ssh testserver01 'dsmc q b "${ARCHIVE_DIR}*" -sub=yes -querysummary -inactive -fromd="${BACKUP_DATE}"' Thank you. (3 Replies)
Discussion started by: zam
3 Replies

2. Shell Programming and Scripting

Test exit status of last cmd via ssh

see below for a housekeeping script which constructs an ssh cmd using some server/path/sudo info found in $HRINST. the script should hop to each server and if it finds a file to cleanup, moves it to the archive dir if there is nothing to move, it should report so and email the output ... (3 Replies)
Discussion started by: jack.bauer
3 Replies

3. Shell Programming and Scripting

how to assign value to the variable through ssh

Hi All, i am writing a shellscript to compare cksum of the file in local machine and after copying to remote machine. i am not able to assign command output value to variable in remote machine through SSH. PFB code for this. code: ###### Get File size of the file in local remote system ... (3 Replies)
Discussion started by: katamsivakumar
3 Replies

4. UNIX for Advanced & Expert Users

SSH key works from CMD line not script

OK , .. This is an odd one. I have a new server and I need to have a tunnel open to it. I have this exact process running on a few others but this new one I just got is not allowing the script to connect. I set up my users account and ssh keys from the server that will host the tunneling i... (6 Replies)
Discussion started by: jeffsandman0035
6 Replies

5. Programming

assign array with a local var???

Hi all, I am just wondering is this (below code) valid in programming int xx = 10110; int i; long yy = {1,2,3,4,5,6,7,8,xx}; I compiled this using gcc will all working option successfully without getting any warning or error. I didn't see this kind of code in my past... (7 Replies)
Discussion started by: zing_foru
7 Replies

6. UNIX for Advanced & Expert Users

assign array with a local var???

topic moved to programming (0 Replies)
Discussion started by: zing_foru
0 Replies

7. Shell Programming and Scripting

assign var with set=a[5] not working

Hi Experts, I'm having issue in assigning var with special character , please see below for complete details. $ echo $SHELL /bin/csh $ cat bp abd/asd/a $ awk -F "/" '{print $NF}' bp | awk '{print $1}' a $ set a=`awk -F "/" '{print $NF}' bp | awk '{print $1}'` $ echo $a ... (15 Replies)
Discussion started by: novice_man
15 Replies

8. Shell Programming and Scripting

Are free public shells for ssh tunneling safe?

Is it secure to use free shells for ssh tunneling? Can the shell provider see and log the sites I visit and passwords I enter? I'm new to this thing and couldn't find info on google :o (5 Replies)
Discussion started by: rafunk
5 Replies

9. Red Hat

Free SSH Client other than PUTTY

Is there any Better FREE SSH client similar to Secure CRT ? We are working on cluster db servers. PROD/DEV/UAT/QA/TEST server hostnames are just one letter differences. it always confuse me to which one I am logging in. So I am looking for a free SSH client, for windows where I can store... (4 Replies)
Discussion started by: johnveslin
4 Replies

10. Shell Programming and Scripting

assign shell var output of cmd "wc"

how do I feed output of "wc" to a shell script variable "countBcp"? (2 Replies)
Discussion started by: devy
2 Replies
Login or Register to Ask a Question