LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-17-2020, 02:08 AM   #16
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,091

Rep: Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365

Quote:
Originally Posted by ncnaveen_arasu View Post
Hi

thanks for the suggestion. we are in restricted environment where third party application/software cant be installed.
or else would have been tried.
thanks for advice,will be try using it in other environment.
you do not need to install shellcheck, it is an online tool which can be used within a browser. Or as a standalone app without installation, if downloaded.
Anyway it is much faster than posting to a forum and waiting for an answer.

Last but not least you need to learn and understand what's going on, otherwise you will hardly be able to implement anything. Go step by step.
For example based on post #13 you can check what will be stored in the variable swap.
Next you can check how an if construct works and how can you write a conditional expression.

Last edited by pan64; 06-17-2020 at 02:17 AM.
 
1 members found this post helpful.
Old 06-17-2020, 08:08 AM   #17
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,792

Rep: Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002
Quote:
Originally Posted by ncnaveen_arasu View Post
Hi New to forum and Linux too..and was not knowing that i can show gratitude by clicking on green button. So was marking it as helpful.
Thanks for the suggestion.
No need, but you do need to pay attention and apply what you're told. This thread was almost IDENTICAL to your other thread, and you've been told about the 'team' before as well.
 
1 members found this post helpful.
Old 06-17-2020, 12:36 PM   #18
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,818

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by ncnaveen_arasu View Post
Hi Team,

trying to monitor swap memory usage from below script.

#! /bin/bash

swap=$(free | awk '/Swap/{printf ("%.2f%"), $3/$2*100}')

if [ $swap -lt 20% ]
then
echo "OK - Swap Memory at $swap %"
exit 0
elif [[ $swap -ge 20% && $swap -lt 40% ]]
then
echo "Warning - Swap Memory at $swap %"
exit 1
elif [ $swap -ge 40% ]
then
echo "CRITICAL - Swap Memory at $swap %"
exit 2
else
echo "UNKNOWN - unable to retrieve Swap Memory usage"
exit 3
fi

================================================================

But getting error as below. Not sure where am doing wrong. Can someone please assist.

./swap.sh: line 5: [: 7.40%: integer expression expected
./swap.sh: line 9: [[: 7.40%: syntax error: invalid arithmetic operator (error token is ".40%")
./swap.sh: line 13: [: 7.40%: integer expression expected
UNKNOWN - unable to retrieve Swap Memory usage

Thanks
The tests you are doing ("-ge") are for integers. Omit the percent sign from the output of your printf() and change the tests to something like:
Code:
if [ $SWAP -ge 90 ]; then
    echo "Yikes"
fi
Or use a scripting language other than shell. Perl and/or Python can deal with floating point numbers w/o problems.

HTH...
 
Old 06-17-2020, 02:04 PM   #19
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,947

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
It's not really necessary to do all this $SWAP stuff - Linux would tell you if you if things had got critical.
You would most likely get only a few seconds to identify and kill a runaway process before the machine crashes.
 
Old 06-18-2020, 05:00 PM   #20
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,885
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
As pan64 points out, you can syntax check using online tools.

In my signature is a blog about bash debugging, it also contains bash references.

There's a ton you can do just using various coding and debugging techniques in your script.

As TB0ne notes, you have to do these diagnostics on your own to learn them. My thought processes when I hit a coding challenge is that I remind myself that a lot of people can likely do this stuff nearly in their sleep, and that it is not rocket science, so I can do it myself.
 
1 members found this post helpful.
  


Reply

Tags
scripting, shell script



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Live DVD runs out of memory - using swap - free memory doesn't help at upgrade .... LiNuXkOlOnIe Linux - Distributions 3 06-09-2013 09:35 PM
memory metric to monitor memory usage or swap? karlochacon Linux - Newbie 5 08-13-2011 03:49 PM
process, memory, swap, virtual memory wakatana Linux - Hardware 1 08-31-2009 07:55 AM
Swap Memory / Virtual Memory in Fedora Core 6 Jojo_CFT Linux - Newbie 2 10-15-2007 04:23 AM
Difference between Swap Virtrual memory and Swap Parition Nappa Slackware 4 11-27-2003 07:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration