Solved

UNiX Script filesystem space usage

Posted on 2016-07-30
19
67 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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…
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.
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.

914 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

20 Experts available now in Live!

Get 1:1 Help Now