Solved

UNiX Script filesystem space usage

Posted on 2016-07-30
19
59 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
Comment Utility
output=$(df | egrep "([89][0-9]|100)%")
echo ${output}
0
 

Author Comment

by:Frog_1337
Comment Utility
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
Comment Utility
try this

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

Assisted Solution

by:omarfarid
omarfarid earned 125 total points
Comment Utility
correction

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

Author Comment

by:Frog_1337
Comment Utility
No its only echoing the command not the output
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 125 total points
Comment Utility
note to use ` not ' in the first line
0
 

Author Comment

by:Frog_1337
Comment Utility
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
Comment Utility
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
Comment Utility
If you have a working command just add echo like this:

echo $(your working command)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Author Comment

by:Frog_1337
Comment Utility
When I try the echo$(command) I still do not get output
0
 
LVL 76

Assisted Solution

by:arnold
arnold earned 125 total points
Comment Utility
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
Comment Utility
Still no output. Im thinking I may have to take a different route or something
0
 
LVL 76

Assisted Solution

by:arnold
arnold earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
It was the case sensitive issue thank you
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
Comment Utility
You're welcome ;)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
improve Shell script 5 137
UNiX Script filesystem space usage Part2 54 72
unix example issues 18 44
unix solaris snoop command 6 43
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

771 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

12 Experts available now in Live!

Get 1:1 Help Now