Disk Space Script to direct output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Disk Space Script to direct output
# 1  
Old 04-14-2015
Disk Space Script to direct output

Hi,

I am working on Sun Solaris 5.10 and want to direct the output from a disk space check script to an output file;

Code:
#!/bin/bash
CURRENT=$(df -k /log/logs | grep /log/logs | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=30
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
echo "Remaining free space is low" > output.txt
else
echo "Space seems ok" > output.txt
fi

It does not seem to be working with the first part and just displays 'space seems ok' while the current space is above the threshold. Any possible hints, indicators would be helpful. Thanks in advance.

Last edited by vgersh99; 04-14-2015 at 11:47 AM.. Reason: code tags, please!
# 2  
Old 04-14-2015
start by adding set -x to your script and see what the script does.
# 3  
Old 04-14-2015
Thanks it is really helpful, it seems it is not able to pick the value up from the current

Code:
+ + df -k /log/logs
+ grep /log/logs
+ awk { print $5}
+ sed s/%//g
CURRENT=
+ THRESHOLD=30
+ [  -gt 30 ]
+ echo Space seems ok
+ 1> output.txt

# 4  
Old 04-14-2015
I'd suggest debugging df -k /log/logs | grep /log/logs | awk '{ print $5}' | sed 's/%//g' one "pipe" at a time starting from the left...
# 5  
Old 04-14-2015
Thanks, so it seems it does not work after "grep" as it shows below;

Code:
+ + df -k /log/logs
CURRENT=Filesystem            kbytes    used   avail capacity  Mounted on
/log             20643785 8189598 12247750    41%    /log

Code:
+ + grep /log/logs
+ df -k /log/logs
CURRENT=

This is where it is getting a little confusing, used the same script on another server and it works but instead of directing output to a file it emails instead;

Code:
+ + df -k /log/logs
+ grep /log/logs
+ sed s/%//g
+ awk { print $5}
CURRENT=66
+ THRESHOLD=80
+ [ 66 -gt 80 ]

# 6  
Old 04-14-2015
How about...:
Code:

df -k /log/logs |awk '$1 ~ "^/log"{ print $5+0}'

# 7  
Old 04-14-2015
Code:
df -k /log/logs |awk '$1 ~ "^/log"{ print $5+0}'
awk: syntax error near line 1
awk: bailing out near line 1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Disk space script

i have 3 servers and i am checking for the disk space of a specific mount-point, should not be more than 85 % considering example as below server1 mountpoint_1 has 70% diskutilization server2 mountpoint_1 has 80% diskutilization server3 mountpoint_1 has 7% diskutilization now when it... (6 Replies)
Discussion started by: abhaydas
6 Replies

2. UNIX for Beginners Questions & Answers

Cutting disk space output

Running this code df -h | head -2 | awk '{print $8}' Gives me the following output: %iused 6% What I'm trying to do is get the 6% but I'm having trouble doing this using cut -c, I think that this could be because the text is on different lines; is there a way of doing this? (8 Replies)
Discussion started by: $shell_Learner
8 Replies

3. Shell Programming and Scripting

Manipulating sed Direct Input to Direct Output

Hi guys, been scratching round the forums and my mountain of resources. Maybe I havn't read deep enough My question is not how sed edits a stream and outputs it to a file, rather something like this below: I have a .txt with some text in it :rolleyes: abc:123:xyz 123:abc:987... (7 Replies)
Discussion started by: the0nion
7 Replies

4. Shell Programming and Scripting

Disk Space Output

I am very new to unix and Linux, So I have a question about LINUX and AIX. What LINUX and AIX commands can be used to get the following output: 071912 GB blocks Free %Iused Mounted on 071912 5.00 4.64 8% / 071912 15.00 9.44 38% /usr 071912 6.00 2.56 58% /var 071912 15.00 12.88 15% /tmp... (1 Reply)
Discussion started by: najeemsarwat
1 Replies

5. Emergency UNIX and Linux Support

Disk space script output in color

I'm connecting to 15 servers in using ssh and storing disk space details of each server in a text file Finally , I'm emailing that text file at the particular id using mail -x . The report looks something like this. Filesystem size used avail capacity Mounted on /proc ... (30 Replies)
Discussion started by: ajaypatil_am
30 Replies

6. Shell Programming and Scripting

how to direct scp output to a file in bash shell or script

I can run this from the command line: scp -i identfile /path/file_to_send remotelogin@remotebox:/path_to_put_it/file_to_send and I get: file_to_send 100% |***************************************************************************| 0 00:00 but if I do: scp -i identfile... (6 Replies)
Discussion started by: NewSolarisAdmin
6 Replies

7. Shell Programming and Scripting

Script for Disk space

:( Hi All, i have 4 linux server for which i want set up script to monitor the disk space ... here my problem is i want the output like graph... also it should reflect in monitor ...as non stop process.. can any one suggest me any way where i can implement the script? ... (3 Replies)
Discussion started by: Shahul
3 Replies

8. Shell Programming and Scripting

Direct the output of a script to a log file

Hi, I have a script to compare 2 files. file1=$1 file2=$2 num_of_records_file1=`awk ' END { print NR } ' $file1` num_of_records_file2=`awk ' END { print NR } ' $file2` i=1 while do sed -n "$i"p $file1 > file1_temp sed -n "$i"p $file2 > file2_temp diff file1_temp... (5 Replies)
Discussion started by: autosys_nm
5 Replies

9. Shell Programming and Scripting

Disk space script

Hi all, Can any one help me in making a disk space script in solaris 8/9 for instance i only want to get those partitions whose diskspace has exceed 70%. Any volunteer? Cheers! BR/asad (8 Replies)
Discussion started by: asadlone
8 Replies

10. Programming

Direct disk access

Is there any way to write to disk sector by sector, without any files, filesystems etc. I did that in DOS, but that was DOS. (3 Replies)
Discussion started by: Lopatonosec
3 Replies
Login or Register to Ask a Question