- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: A test command parameter is not valid
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-29-2007 04:58 AM
тАО03-29-2007 04:58 AM
The script is as follows:
# script name: chkdisk_usage.sh
# for: Checking file systems usage greater than 97% full!
PATH=/usr/bin:/usr/sbin;export PATH
>/tmp/file.out
l1="----------"
line () {
echo ${l1}${l1}${l1}${l1}${l1}${l1}${l1}
}
header="Filesystem kbytes used avail %used Mounted on"
tempfile=/tmp/chkdisk_usage.temp
(line
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,
$6,$7}'
line
bdf|/usr/bin/grep -vi kbytes|sort>$tempfile
for filesys in `/usr/bin/cat $tempfile|/usr/bin/awk '{print $1}'`
do
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\
n",$1,$2,$3,$4,$5,$6}'
fi
done
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 gdoller@comforce.com
fi
rm $tempfile
Any help would be appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-29-2007 05:07 AM
тАО03-29-2007 05:07 AM
Re: A test command parameter is not valid
WARNINGS
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
HTH
Duncan
I am an HPE Employee
- Tags:
- bdf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-29-2007 09:25 AM
тАО03-29-2007 09:25 AM
Re: A test command parameter is not valid
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 $().)
- Tags:
- evil cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-29-2007 12:58 PM
тАО03-29-2007 12:58 PM
Solutionbdf | while read FS TOT USED AVL PCT MNT
do
[ "$FS" = "Filesystem" ] && continue
[ "$TOT" = "" ] && read TOT USED AVL PCT MNT
...
...put your code here
...
done
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/chkdisk_usage.sh
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:
#!/usr/bin/sh
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:
TMPFILE=/var/tmp/chkdsk_usage.$$
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-29-2007 06:04 PM
тАО03-29-2007 06:04 PM
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.
-Santosh