Solved

UNiX Script filesystem space usage

Posted on 2016-07-30
19
87 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 125 total points
ID: 41735781
try this

OUTPUT=`df | egrep "[89][0-9]|100)%"`
Echo $OUTPUT
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 125 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 125 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 250 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 78

Assisted Solution

by:arnold
arnold earned 125 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 78

Assisted Solution

by:arnold
arnold earned 125 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 125 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 250 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

726 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