I’m coding using python tonight, and I most of the time get out of my way when something gets me interested, enough to fork() away from my original (python-coding) task/s.
The fork() was that I needed to create sample/test files that I can specify the size of. I was experimenting and testing my python codes which rm (deletes) a specific file type (.flv). The catch was that I needed to rm .flv files that were below a certain file size.
The second fork() was that I needed to test the disk size quota I implemented on our NX (OpenSuse) server for several accounts. I implemented a disk quota so other users won’t use up all the hard disk space, which happened some time ago. So I needed to test whether the quota I implemented was working
So what I did was I used the really old (yet still very cool) dd tool. dd can help me with both of my fork()s. using the command:
$ dd if=/dev/zero of=test3.flv bs=2k count=1
I was able to solve the dilemmas I encountered with my fork()s using the dd tool. The previous command basically creates a file with NULL characters with a filename test3.flv. The size of file3.flv is 2KB, actually. For the quota that I implemented (using the edquota tool, btw), I just use the following command:
$ dd if=/dev/zero of=sometestfile bs=400M count=1
Where the directory quota is 200 MB. The output should be an error, since the hard limit I implemented was only 200 MB. A sample is shown below:
# quotaon -augv
then I issue:
# repquota -as|grep eee13
Which has the (truncated) output:
eee13_200648971 -- 23304 0 196M 2419 0 0 eee13_200649412 -- 42368 0 196M 3815 0 0 eee13_200652661 -- 53516 0 196M 996 0 0 eee13_200654274 -- 21664 0 196M 646 0 0 eee13_200659116 -- 50360 0 196M 1072 0 0 eee13_200663185 -- 14236 0 196M 486 0 0 eee13_200664708 -- 35568 0 196M 819 0 0 eee13_200676629 -- 23876 0 196M 581 0 0
Which I further check by:
# su - eee13_20060033
Which produces the following output (with error of course):
eee13_200600333@opensuse:~> dd if=/dev/zero of=samplefile bs=400M count=1 sda3: write failed, user block limit reached. dd: writing `samplefile': Disk quota exceeded 1+0 records in 0+0 records out 184619008 bytes (185 MB) copied, 0.770389 s, 240 MB/s
Checking to see what happened:
eee13_200600333@opensuse:~> ls -lh total 177M drwxr-s--- 2 eee13_200600333 eee13_hdef 4.0K 2007-06-19 13:10 bin drwx--S--- 2 eee13_200600333 eee13_hdef 4.0K 2007-08-05 21:58 Desktop drwxr-s--- 2 eee13_200600333 eee13_hdef 4.0K 2007-06-19 13:10 Documents drwxr-s--- 2 eee13_200600333 eee13_hdef 4.0K 2007-07-06 10:50 lab1 drwxr-s--- 5 eee13_200600333 eee13_hdef 4.0K 2007-06-29 10:58 lab2 drwxr-s--- 3 eee13_200600333 eee13_hdef 4.0K 2007-07-13 09:51 lab3 drwxr-s--- 2 eee13_200600333 eee13_hdef 4.0K 2007-07-20 10:19 lab4 drwxr-s--- 2 eee13_200600333 eee13_hdef 4.0K 2007-07-13 09:16 lectures -rw-r----- 1 eee13_200600333 eee13_hdef 316 2007-07-20 09:37 Makefile_template drwxr-s--- 2 eee13_200600333 eee13_hdef 4.0K 2007-07-27 11:24 mp1 drwxr-s--- 2 eee13_200600333 eee13_hdef 4.0K 2007-06-19 13:10 public_html -rw-r----- 1 eee13_200600333 eee13_hdef 177M 2007-08-05 21:59 samplefile drwxr-s--- 2 eee13_200600333 eee13_hdef 4.0K 2007-07-13 10:35 testfolder
Success! The user can’t fill his/her directory with more than 200 MB. And so this is what I did with my python code testing as well. I was able to successfully simulate my code’s behavior using the very excellent tool dd.
Of course, dd has much much more use than creating files with NULL data. But that’s for another blog for another day…..I need to work some more….