Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Languages and Scripting
Showing results for 
Search instead for 
Did you mean: 

A test command parameter is not valid

Go to solution
Tim Griffin
Occasional Visitor

A test command parameter is not valid

Receive the following error message in script that checks the file system usage - /usr/local/bin/[27]: 28: A test command parameter is not valid.

The script is as follows:

# script name:
# for: Checking file systems usage greater than 97% full!

PATH=/usr/bin:/usr/sbin;export PATH

line () {
echo ${l1}${l1}${l1}${l1}${l1}${l1}${l1}

header="Filesystem kbytes used avail %used Mounted on"

echo "hostname: `/usr/bin/hostname`\nAs of `date`\n\
The following file systems exceeding 97% disk usage!\n"
echo $header|/usr/bin/awk '{printf"%-19s%12s%12s%12s%9s%9s%5s\n",$1,$2,$3,$4,$5,

bdf|/usr/bin/grep -vi kbytes|sort>$tempfile
for filesys in `/usr/bin/cat $tempfile|/usr/bin/awk '{print $1}'`

fsize=`/usr/bin/grep $filesys $tempfile|/usr/bin/awk '{print $5}'|sed 's/%//g'`

if [ $fsize -gt 97 ];then
/usr/bin/grep $filesys $tempfile|/usr/bin/awk '{printf"%-19s%12s%12s%12s%9s%14s\

line) >/tmp/chkdisk_usage.log

cat /tmp/chkdisk_usage.log | cut -c60-90 |cut -d" " -f1-20 -s>/tmp/file.out
grep -q dev/vg /tmp/chkdisk_usage.log
if [ $? = 0 ]; then

cat /tmp/file.out |grep "%" | /usr/sbin/sendmail
rm $tempfile

Any help would be appreciated.
Duncan Edmonstone
Honored Contributor

Re: A test command parameter is not valid

without actually examining your script in detail, I would hazard a guess that the system it fails on has file systems with long names... that can cause bdf to split its output over 2 lines which will mess up your text formatting based on columns. This is a warning from the bdf man page:

If file system names are too long, the output for a given entry is
displayed on two lines.

I usually use mount -p and feed this into multiple 'df -k' statements to do this without suffering the problem with bdf




Dennis Handly
Acclaimed Contributor

Re: A test command parameter is not valid

It would be helpful if you could point to the line 27 or 28 with the "if".
I'm assuming it is:
if [ $fsize -gt 97 ];then

As Duncan said, $fsize is probably not numeric or it is an empty string. If you were comparing strings, the proper solution would be to quote it: "$fsize"

>if [ $? = 0 ]; then

This should really be: $? -eq 0

>for filesys in `/usr/bin/cat $tempfile|/usr/bin/awk '{print $1}'`
>cat /tmp/chkdisk_usage.log | cut -c60-90 |cut -d" " -f1-20 -s ...
>cat /tmp/file.out |grep "%" | ...

There is no need to use cat on these lines. Just put the filename on awk, cut or grep.

(You also should replace `` by $().)
Bill Hassell
Honored Contributor

Re: A test command parameter is not valid

bdf will mess up your code completely as soon as you have a long sourcefile (very typical for nfs or cifs mounts). bdf will also mess up your code because the columns are unstable. Anytime I see cut -c I get very worried about the reliability of the code. bdf will change the column numbers when necessary. Here is the way to parse each bdf line without regard to split lines or variable number widths:

bdf | while read FS TOT USED AVL PCT MNT
[ "$FS" = "Filesystem" ] && continue
[ "$TOT" = "" ] && read TOT USED AVL PCT MNT
...put your code here

Other notes:

/usr/bin/grep and /usr/bin/awk

are not necessary. All reliable scripts will establish their own PATH (as you have) to prevent corruption from users that are playing around. Just use the command name rather than the fullpath. For total paranoia, you can:

unset bdf grep cut awk sort sed

which guarantees that you will get the 'real' bdf, etc.

When you test numeric items, use -eq since = is designed for strings while -eq is designed for numeric tests. And as mentioned, all of the filter commands you are using (cut awk grep sed, etc) do their own file reading. Use of cat is unnecessary.

The error:
"A test command parameter is not valid."
almost always means that one of the parameters being tested is null. To see which one, run your script like this:

sh -x /usr/local/bin/

You'll probably see the error like this:

+ [ -gt 97 ]

which says that $fsize was set to null.

Always start your scripts with "sh-bang
" which is:
to insure that the correct shell will be used to run your script.

Whenever you define a temp file, always define a disposal. Otherwise, your script will litter up the temp directories. And if two or more users run your script at the same time, they will clobber eaqch other's temp file. Do something like this:

trap "rm -f $TMPFILE;exit" 0 1 2 3 15


Or you can just use the attached script which accomplishes all your goals (monitoring disk space) and will notify you in several different ways. This script can monitor different percentages for each filesystem.

Bill Hassell, sysadmin
Trusted Contributor

Re: A test command parameter is not valid


On line 27
if [ $fsize -gt 97 ];then
u may be getting a null value or a non-numeric value,

the best way is to debug ur script by adding

set -vx

at the beginning and pausing the run after if
statement by adding line

read a

after if statement.

Just debug and u will find where the problem is.