how to get the correct reading of diskspace


 
Thread Tools Search this Thread
Operating Systems Linux how to get the correct reading of diskspace
# 1  
Old 09-09-2008
Error how to get the correct reading of diskspace

What has happened.

I beleive the diskpace is not showing the correct reading.

Is there another command to use to get the diskspace without using du -h?


Is there another command linux uses.

The reason i am assuing this i cleared the log of a process that started using nohup for example.

nohup script1.sh > script1.log 2>&1


Now the script1.log was consuming all the diskspace

So while the process is still running i cleared the log using cat /dev/null > script1.sh then ran rm -rf script1.sh

after this was done the diskspace is remaining the same size even though the file removed was at least 20% to 30% use of diskspace.

Currently I cannot kill the script at the moment as it is a n important script. So i just wanted to know if there is a work around to get the correct disk size without killing the process in the mean time.

Any help would be appreciated.
# 2  
Old 09-09-2008
The space remains occupied while the process holds the file handle open.
# 3  
Old 09-09-2008
Do you know of way to rotate the log file controlled by nohup? That way i will not have to clear it in the future.
# 4  
Old 09-10-2008
I'm sorry, but I don't think it can be done. Hmm, that would actually be a rather useful helper application to have: cat with "close and reopen output file" when sent a signal. Maybe such a thing exists, but you would have to use it when starting the job.
# 5  
Old 09-10-2008
Quote:
Originally Posted by jonathan184
So while the process is still running i cleared the log using cat /dev/null > script1.sh then ran rm -rf script1.sh
I presume you meant script1.log, not script1.sh.

Sometimes the cat /dev/null > script1.log (or just >script1.log on its own) is enough. When the next output is written to the file you can end up with a sparse file, where the file size is reported as quite large, but the file only occupies a small space on disk.

The big problem was that you removed the log file with rm, which meant that you could no longer truncate the log.

Here is an example where I create a "log" file, and part way through writing to it, I "flatten" the file. You can see that the file size continues to increase, but the disk usage reported by du drops:

Code:
# while sleep 1 ; do dd if=/dev/zero bs=1048576 count=1 2>/dev/null ; done > /tmp/logfile &
[1]     20489
# ls -l /tmp/logfile
-rw-r--r--   1 root       sys        2097152 Sep 10 07:15 /tmp/logfile
# ls -l /tmp/logfile ; du -ks /tmp/logfile
-rw-r--r--   1 root       sys        8388608 Sep 10 07:15 /tmp/logfile
11264   /tmp/logfile
# ls -l /tmp/logfile ; du -ks /tmp/logfile
-rw-r--r--   1 root       sys        9437184 Sep 10 07:15 /tmp/logfile
11264   /tmp/logfile
# ls -l /tmp/logfile ; du -ks /tmp/logfile
-rw-r--r--   1 root       sys        15728640 Sep 10 07:15 /tmp/logfile
27648   /tmp/logfile
# ls -l /tmp/logfile ; du -k /tmp/logfile
-rw-r--r--   1 root       sys        23068672 Sep 10 07:15 /tmp/logfile
27648   /tmp/logfile
# > /tmp/logfile
# ls -l /tmp/logfile ; du -k /tmp/logfile
-rw-r--r--   1 root       sys        33554432 Sep 10 07:15 /tmp/logfile
3072    /tmp/logfile
# ls -l /tmp/logfile ; du -k /tmp/logfile
-rw-r--r--   1 root       sys        35651584 Sep 10 07:15 /tmp/logfile
11264   /tmp/logfile
# ls -l /tmp/logfile ; du -k /tmp/logfile
-rw-r--r--   1 root       sys        36700160 Sep 10 07:15 /tmp/logfile
11264   /tmp/logfile
# kill %1
#
[1] + Terminated               while sleep 1 ; do dd if=/dev/zero bs=1048576 count=1 2>/dev/null ; done > /tmp/logfile &
#

# 6  
Old 09-10-2008
Cool explaination thank you. That makes sense on what you said.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Check free diskspace

Hi all, I would like to know what was the free disk space available in my system for last two days back. I know how to check free disk space by command below. df -h But i want to know the same outcome for last two days back. Please help me. Reg, Mastan (5 Replies)
Discussion started by: mastansaheb
5 Replies

2. Shell Programming and Scripting

DiskSpace Error

Hi, While am preparing the script for diskspace for different partitions different threshhold limit. am getting below error: ./test.sh: syntax error at line 5: `space=$' unexpected Script ==== #!/bin/sh df -h |grep -v '/oradata2'|grep -v '/orabkp' |grep -v '/oradata5' | awk '{ print $5... (7 Replies)
Discussion started by: Pavan83
7 Replies

3. Shell Programming and Scripting

[ask]elimination with diskspace

dear all, i want elimination file with disk space for example: $ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 62G 19G 41G 31% / /dev/sda1 99M 13M 82M 13% /boot tmpfs 1014M 0... (2 Replies)
Discussion started by: zvtral
2 Replies

4. Solaris

graphical diskspace analyzer

Hi all, recently I took over the admin task for a solaris 5.10 machine. Being a little bit familiar with debian systems Solaris is up to now a complete mystery to me. The first thing I would like to have is a graphical diskspace analyzer. I mean something like BaoBab under gnome. I there a... (2 Replies)
Discussion started by: sly_dunbar
2 Replies

5. Shell Programming and Scripting

ASM Diskspace

Hi I want to check Oracle ASM disk status through a PERL script. Script flow would be like this ... 1. Its taking diskgroup name in the command line... 2. Connect to Oracle database 3. If connection error send a critical message. Plz replyyyyyyy...... (1 Reply)
Discussion started by: Harikrishna
1 Replies

6. Shell Programming and Scripting

to compute diskspace

Guys, have any idea for the script like this? also to compute w/ decimal. thanks a=10 b=20 c=30 d=40 if a < b then ( a -b)*1024 = free space b + (c -d) = total space if a > b then (b / d)*1024 = cpu (3 Replies)
Discussion started by: kenshinhimura
3 Replies

7. AIX

Help ... Java not reading correct AIX system time.

I have Java 1.4.2 (IBM AIX build ca142-20050929a SR3) installed on AIX 5.3. My system time is set correctly and both date and smitty confirm the correct date, time, and timezone: #date Thu Sep 21 15:12:42 EDT 2006 However, when I check the sytem time in Java... (2 Replies)
Discussion started by: dave521
2 Replies

8. UNIX for Dummies Questions & Answers

Diskspace

Hi there, pls help me, i have a problem, how i can find out the disk amount of each harddisk per command (not the on label on the Harddisk) i need it on HP UX and Sun. can anybody helb me???? pls thanks Scotty (1 Reply)
Discussion started by: scotty
1 Replies

9. UNIX for Dummies Questions & Answers

Linux diskspace usage

when /var directory of my machine gets filled up (85%) i removed some old logs. but after cleaning df -k command still shows that /var is still 85% full. It can detect the actual disk space only after I restart the machine. Is there a way to force df to reflect actual free space without... (1 Reply)
Discussion started by: necro
1 Replies

10. UNIX for Dummies Questions & Answers

diskspace usage info

Anybody can help me? I need to know a specified folder diskspace usage, that's how much bytes that folder and its files/folders below spend on my storage. Thanks (2 Replies)
Discussion started by: nusajunus
2 Replies
Login or Register to Ask a Question