Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

UNiX Script filesystem space usage

Posted on 2016-07-30
19
Medium Priority
?
103 Views
Last Modified: 2016-07-30
I am working on a simple script and I cannot get the command to execute. I am certain I am missing a quote somewhere but cannot get the command to run. The script I have is below. The command by itself executes. When attempting to run in a script it will not

#! /bin/sh

OUTPUT="$(df | egrep "([89][0-9]|100)%")"
Echo "$(OUTPUT)"
0
Comment
Question by:Frog_1337
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 4
  • +1
19 Comments
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 41735730
output=$(df | egrep "([89][0-9]|100)%")
echo ${output}
0
 

Author Comment

by:Frog_1337
ID: 41735769
This is not working. The output is blank where as the command ran by itself gives the filesystems over the percentage
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 500 total points
ID: 41735781
try this

OUTPUT=`df | egrep "[89][0-9]|100)%"`
Echo $OUTPUT
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 500 total points
ID: 41735783
correction

OUTPUT=`df | egrep "[89][0-9]|100%"`
Echo $OUTPUT
0
 

Author Comment

by:Frog_1337
ID: 41735799
No its only echoing the command not the output
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 500 total points
ID: 41735802
note to use ` not ' in the first line
0
 

Author Comment

by:Frog_1337
ID: 41735811
Still not working. I just need this command to echo an output

df | egrep "([89][0-9]|100)%"
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 41735814
please run below command then post output:

df | egrep "[89][0-9]|100%"
0
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 1000 total points
ID: 41735826
If you have a working command just add echo like this:

echo $(your working command)
0
 

Author Comment

by:Frog_1337
ID: 41735832
(258)==> df | egrep "([89][0-9]|100)%"
/dev/vg00/sysadmlv 2097152 1669080  401479   81% /sysadm
wins04:root:[/]
(259)==>
0
 

Author Comment

by:Frog_1337
ID: 41735833
When I try the echo$(command) I still do not get output
0
 
LVL 80

Assisted Solution

by:arnold
arnold earned 500 total points
ID: 41735845
Your double quotes in the assignment might be the issue,
Opening quotes might have been closed by the quotes for the egrep.
Either escape the inner quotes, remove the outer or try the following.

output=$(df| egrep '([89][0-9]|100)\%' )
echo $output
0
 

Author Comment

by:Frog_1337
ID: 41735854
Still no output. Im thinking I may have to take a different route or something
0
 
LVL 80

Assisted Solution

by:arnold
arnold earned 500 total points
ID: 41735857
look at the output of df
Try using df -k instead.
df |egrep '\%'
Do you have all but the first rows displayed?
0
 

Author Comment

by:Frog_1337
ID: 41735863
This is hpux 11.1 so no -k function.
df |egrep '\%' Gives full df output when ran normally
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 500 total points
ID: 41735880
your out put is correct, as you posted:

(258)==> df | egrep "([89][0-9]|100)%"
/dev/vg00/sysadmlv 2097152 1669080  401479   81% /sysadm

now try this:

OUTPUT=`df | egrep "([89][0-9]|100)%"`
echo $OUTOUT
0
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 1000 total points
ID: 41735884
>> When I try the echo$(command) I still do not get output
Is does for me, you must be doing something wrong. Can you post your commands + output (copy from screen), maybe you're echoing Output and not output - casing matters as you may know.

$ df | egrep "([89][0-9]|100)%"
devfs                                    353       353         0   100%       611         0  100%   /dev
map -hosts                                 0         0         0   100%         0         0  100%   /net
map auto_home                              0         0         0   100%         0         0  100%   /home
$ output=$(df | egrep "([89][0-9]|100)%")
$ echo ${output}
devfs 353 353 0 100% 611 0 100% /dev map -hosts 0 0 0 100% 0 0 100% /net map auto_home 0 0 0 100% 0 0 100% /home
$ echo $(df | egrep "([89][0-9]|100)%")
devfs 353 353 0 100% 611 0 100% /dev map -hosts 0 0 0 100% 0 0 100% /net map auto_home 0 0 0 100% 0 0 100% /home
$ 

Open in new window

0
 

Author Comment

by:Frog_1337
ID: 41735942
It was the case sensitive issue thank you
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 41735975
You're welcome ;)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question