- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 04:31 AM
07-03-2002 04:31 AM
i have the following script :
#!/bin/sh
set -x
top 1>top.out
cat top.out | egrep '^Memory' | awk ' {print $2 " " $4}' > top2.out
sed 's/M/p' top2.out
rm top.out
exit 0
In order to get the % of free memory, i want to get the total memory and the free memory from the command top. And then I would do some aritmethic operation on it. But I get the following error :
sed: command garbled: s/M/p
any idea ?
thank you
alfredo
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 04:38 AM
07-03-2002 04:38 AM
Re: script problem
Try with :
sed 's/M/p/' top2.out
Regards,
Fr??d??ric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 04:50 AM
07-03-2002 04:50 AM
Re: script problem
Try these changes:
# top -d 1 -f top.out
...the -f option pushes the output to the file.
# sed -e '/M/'p top2.out
...to print the Memory line...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 04:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 04:57 AM
07-03-2002 04:57 AM
Re: script problem
use top -f top.out
This gives the top output written clearly
Then work on the file contents.
cat top.out | egrep '^Memory' | awk ' {print $2 " " $4 " "$5 " " $7 " " $8 " "$9}'
steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 05:01 AM
07-03-2002 05:01 AM
Re: script problem
I just refined your script like this
# cat top_script
#!/bin/sh
set -x
top -d 1 -f top.out
cat top.out | egrep '^Memory' | awk ' {print $2 " " $4}' > top2.out
sed 's/M/p/' top2.out
rm top.out
exit 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 06:53 AM
07-03-2002 06:53 AM
Re: script problem
#!/bin/sh
set `top -d 1 2>&1 | awk '/^Memory/{sub(/K/,"",$2);sub(/K/,"",$8);print $2 " " $8}'`
echo `expr 100 \* $2 / $1` %
The first line will extract the total and free memory and set it to $1 and $2 respectivelly (via the "set" command).
The second line will calculate the percentage and display the results.
example-
13 %
A perl routine would look nicer, but this shell script will get the job done.
Hope this helps...
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 07:01 AM
07-03-2002 07:01 AM
Re: script problem
I have another suggsestion I got a script form these forums which cgive the o/p like this :
Memory Stat total used avail %used
physical 32764.0 24296.4 8467.6 74%
active virtual 16899.8 10480.4 6419.4 62%
active real 18039.3 10747.2 7292.1 60%
memory swap 26522.5 19504.4 7018.1 74%
device swap 3332.0 3332.0 0.0 100%
So you can just run this and grep on what ever you want to see . I have attached the uncompiled version with the posting