Solved

UNiX Script filesystem space usage

Posted on 2016-07-30
19
73 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
  • 8
  • 5
  • 4
  • +1
19 Comments
 
LVL 37

Expert Comment

by:Gerwin Jansen
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen 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 77

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 77

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 37

Accepted Solution

by:
Gerwin Jansen 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 37

Expert Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix Command -- Challenging  question 7 88
how to run my script during boot in rhel 7 14 144
unix solaris snoop command 6 98
Debugging a shell script 3 25
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Utilizing an array to gracefully append to a list of EmailAddresses
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

813 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now