max_diskspace_used script has syntax error

Bug #926312 reported by Daniel Manrique
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
checkbox (Ubuntu)
High
Marc Tardif

Bug Description

Steps to reproduce:

from trunk:

cd scripts/
./max_diskspace_used /dev/sda1

Result:
Checking maximum disk space available on : /dev/sda1
awk: //dev/sda1/ {print $3}
awk: ^ syntax error

Expected result:
Not a syntax error :)

there's an awk command that looks like:

awk /$disk/ {print $3}

the problem is that $disk may contain forward slashes, so the regex ends up malformed. Not sure how to fix this, but here's the bug report anyway.

Thanks!

ProblemType: Bug
DistroRelease: Ubuntu 11.10
Package: checkbox (not installed)
ProcVersionSignature: Ubuntu 3.0.0-15.26-generic 3.0.13
Uname: Linux 3.0.0-15-generic x86_64
NonfreeKernelModules: wl
ApportVersion: 1.23-0ubuntu4
Architecture: amd64
Date: Fri Feb 3 15:10:18 2012
InstallationMedia: Ubuntu 11.10 "Oneiric Ocelot" - Release amd64 (20111012)
ProcEnviron:
 LANGUAGE=en_CA:en
 PATH=(custom, user)
 LANG=en_CA.UTF-8
 SHELL=/bin/bash
SourcePackage: checkbox
UpgradeStatus: No upgrade log present (probably fresh install)

Related branches

Marc Tardif (cr3)
Changed in checkbox (Ubuntu):
importance: Undecided → High
status: New → In Progress
assignee: nobody → Marc Tardif (cr3)
Revision history for this message
Daniel Manrique (roadmr) wrote :

I merged the linked branch and reran it and I get some more errors :(

sudo scripts/max_diskspace_used /dev/sda
[sudo] password for roadmr:
Checking maximum disk space available on : /dev/sda
Disk space available : 640GB
Disk space used : 479GB
62GB
awk: cmd. line:1: BEGIN{print((640 - 479
awk: cmd. line:1: ^ unexpected newline or end of string
awk: cmd. line:1: 62) / 479
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: 62) / 479
awk: cmd. line:1: ^ unterminated regexp
awk: cmd. line:2: 62)}
awk: cmd. line:2: ^ syntax error
Difference ( > 0.15 fails ) :
awk: BEGIN{exit( > 0.15)}
awk: ^ syntax error
awk: BEGIN{exit( > 0.15)}
awk: ^ syntax error

This is due to my having two partitions on SDA, thus this is what's confusing the script now:

Disk space available : 640GB
Disk space used : 479GB
62GB

Notice the extra CRLF and usage data for the second partition.

A simplistic fix is to head -1 the $fsize variable, but in this case it'd fail the test because the space for the second partition is not considered. I fail the test anyway because my disk is full of crap, but the weird handling of partitions is worrisome.

Revision history for this message
Jeff Lane (bladernr) wrote :

Ran on a server with the standard default partitioning:

bladernr@ubuntu:~$ sudo ./max_diskspace_used sda
Checking maximum disk space available on : sda
Disk space available : 500GB
Disk space used : 496GB
Difference ( > 0.15 fails ) : 0.00806452

Revision history for this message
Daniel Manrique (roadmr) wrote :

Ah so I was using it wrong?

1- I did /dev/sda instead of just sda. Apparently this is the way checkbox calls it too, because I originally saw the error in a submission.
2- I have two partitions with ext3 filesystems, so that threw the script off as well.

Still it'd be good to handle these two cases.

Thanks for also looking at it!

Revision history for this message
Jeff Lane (bladernr) wrote :

No, you were fine. It DOES work either way:

bladernr@klaatu:~/development/cr3-max-diskspace/scripts$ sudo ./max_diskspace_used /dev/sda
[sudo] password for bladernr:
Checking maximum disk space available on : /dev/sda
Disk space available : 500GB
Disk space used : 254GB
216GB
Difference ( > 0.15 fails ) : 0.0638298

I think the problem was just in how it was handling multiple partitions. I put data in the merge request thread but not this one, but on my system, it was initially showing the same awk traces you saw on my hard drive which is partitioned as so:

Number Start End Size Type File system Flags
 1 32.3kB 41.1MB 41.1MB primary fat16 diag
 2 41.9MB 15.8GB 15.7GB primary ntfs boot
 3 15.8GB 231GB 216GB primary ntfs
 4 231GB 500GB 269GB extended
 5 231GB 489GB 258GB logical ext4
 6 489GB 500GB 10.9GB logical linux-swap(v1)

It was successful on my server box that had a fresh install of Precise server using default partitioning... But now it should handle the more common user scenario where they've done wonky things like I have... granted, in my own defense, Windows did the wonky thing, I just shrunk partition 3 down so I could install Ubuntu way back when...

Marc Tardif (cr3)
Changed in checkbox (Ubuntu):
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers