Disk Capacity Shell Script


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Disk Capacity Shell Script
# 8  
Old 03-29-2012
Please post the current version of the script and any error messages verbatim.

Please post the O/S version, blotting anything confidential with X's,
Code:
uname -a

Well spotted Scrutinizer. My cut doesn't misbehave if the parameters are in the wrong order and an example in man cut has the -d before the -f .

Perhaps this is Linux not unix?
This User Gave Thanks to methyl For This Post:
# 9  
Old 03-30-2012
Interestingly, the POSIX specification also says this:
HTML Code:
SYNOPSIS

    cut -b list [-n] [file...]

    cut -c list [file...]

    cut -f list [-d delim] [-s] [file...]
cut

Since the order is explicit in the synopsis, I suspect there must have been some historical implementations that were picky about the order. I don't recall coming across one, but since the error message explicitly says:
Code:
cut: you must specify a list of bytes, characters, or fields

I am guessing this is what this particular implementation wants to see first..
This User Gave Thanks to Scrutinizer For This Post:
# 10  
Old 03-30-2012
I cut-and-pasted some of the code and to my surprise the Unix "cut"-command was giving me a similar error. Things looked kinda spooky for a moment:
Code:
$ echo hello:boss | cut -d: -f2
boss
$ echo hello:boss | cut -d: –f2
usage: cut -b list [-n] [file ...]
       cut -c list [file ...]
       cut -f list [-s] [-d delim] [file ...]

Then this is what set -x showed:
Code:
$ echo hello:boss | cut -d: -f2
+ echo hello:boss
+ cut -d: -f2
boss

$ echo hello:boss | cut -d: –f2
+ echo hello:boss
+ cut -d: $'?\200\223f2'

And this is what od -c showed:
Code:
-   d   '   %   '       –  **  **   f   1

So my guess is the OP has not been using a regular ASCII editor to produce his code...
This User Gave Thanks to Scrutinizer For This Post:
# 11  
Old 03-30-2012
@Scrutinizer
I can't reproduce that effect. Perhaps your own computer or the O/P's is using Unicode not ASCII and my cut/paste is correcting the character? Or, as you suggest the O/P has used a non-unix editor.
The O/P could try editing the script with unix vi (or vim) and retyping the whole line.

The cut with Berkeley unix was a but sensitive to syntax, and we don't know what O/S we have here.
Might be worth trying space characters in the command line as well as following the strict field order:
Code:
cut -f 1 -d '%'

This User Gave Thanks to methyl For This Post:
# 12  
Old 03-30-2012
Right now, if I cut and paste this:
Code:
echo hello:boss | cut -d: -f2

I do not get the error.

If I cut-and-paste this:
Code:
echo hello:boss | cut -d: -f2

I do get the error.

I have tried this on both OSX and Linux, using a Linux computer, a Mac and a Windows computer as intermediary. If I cut and paste the OP's original post into a here document that I run through od -c , I get the same thing...
This User Gave Thanks to Scrutinizer For This Post:
# 13  
Old 03-30-2012
fwiw, I get the same results as Scrutinzer on Windows 7 to RHEL or Solaris (putty).

Last edited by CarloM; 03-30-2012 at 07:43 AM..
This User Gave Thanks to CarloM For This Post:
# 14  
Old 03-30-2012
Brilliant deduction gentlemen.

1) I originally did the cut/paste with IE8 into Reflections 14 telnet which somehow sorted the mess and gave me the correct character.

2) Now if I use IE8 and Microsoft telnet on XP and cut/paste into vi all the funny characters are stripped. I then ran diff to see how different they were.

3) If I use IE8 and cut/paste into Windows Notepad on XP all the funny characters become visible. It's not just the hyphen in the first cut, there are some sloping quotes too. If I then transfer the Notepad version to unix with text file FTP the bad characters are still there.

The script is riddled with them.

Code:
sed -n l scriptname

#!/bin/sh$
# set -x # Uncomment to debug this script$
# set -n # Uncomment to check syntax without any execution$
# Shell script to monitor or watch the disk space$
####Main Script####$
$
df -H | grep -vE '^Filesystem | none' | awk '{ print $1 " " $5 }' | whi\
le read$
do$
 echo $output$
 perc=$(echo $output | awk '{ print $1 }' | cut -d'%' \226f1)$
 part=$(echo $output | awk '{ print $2 }' )$
$
 if [ $perc -ge 90 ]; then$
 echo "Critical Warning: Filesystem \\"$part\\" at \223$perc\224% of capacity\
 | $
 mail -s "Critical Warning: Filesystem \\\224$part\\\224 at \223$perc\224% of\
 capacity\224$
$
 elif [ $perc -ge 70 && $perc -lt 90 ]; then$
 echo "Warning: Filesystem \\"$part\\" at \223$perc\224% of capacity | $
 mail -s "Warning: Filesystem \\\224$part\\\224 at \223$perc\224% of capacity\
\224$
$
 fi$


Advice to O/P is to edit the script with vi or vim and correct all the strange characters. The script has almost certainly been edited with a Microsoft Windows editor not a unix editor and it contains characters from a different character set which are causing the script to fail. If the script was not transferred to the unix server with text file ftp, it will probably also have a spurious ^M (carriage return) character at the end of each line which must be removed.

Last edited by methyl; 03-30-2012 at 08:54 AM..
This User Gave Thanks to methyl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help me with C-shell Script: Disk checking

Hi, i am new in shell script. i have given a task to make a C-shell script. I have list of ip address and device name respectively. For example; cal 1 : 100.21.25.10 cal 2 : 100.21.25.11 cal 3 : 100.21.25.12 cal 4 : 100.21.25.14 and so on... Right now, i have this. #! /bin/csh -f ... (0 Replies)
Discussion started by: lattey
0 Replies

2. UNIX for Dummies Questions & Answers

Tru 64 Disk Capacity Check

i have a query on checking Tru64 disk drives physical capacity. i used hwmgr view devices and saw this disk. 160: /dev/disk/dsk7c COMPAQ BF03688284 bus-3-targ-0-lun-0 checking the model on the internet shows it is a 36.4GB drive. i checked the disk details and saw the... (2 Replies)
Discussion started by: iamnotaguru
2 Replies

3. Shell Programming and Scripting

disk quotas shell script

Hello.. I wrote the following shell script to run disk quotas for assigning limits to users. I need to know the partition which the user has created and mount it. So i copied the partitions (which will be displayed after running fdisk -l) and separted the last line from it and cut the required... (0 Replies)
Discussion started by: kalyanilinux
0 Replies

4. Shell Programming and Scripting

Help with Disk Space script in bash shell

Hi Guys, I'm a newb at shell scripting and successfully attempted a small disk space script (victory!!) but i'm wondering whether it actually takes into consideration KB,MB,GB. Please take a look at the script and advise. ##script to check if file sys has reached threshold. ... (3 Replies)
Discussion started by: Irishboy24
3 Replies

5. Shell Programming and Scripting

Shell script to find filesystem capacity on 50 servers

Hi all, I am new to Unix and I want to write a shell script in a jumpbox for finding the filesystem capacity on 50 unix servers ( by ssh ) and then email the result in HTML format with server name and capacity % to a specific outlook distribution list. any suggestion would be of great help. (17 Replies)
Discussion started by: amitbisht9
17 Replies

6. AIX

how to find out disk capacity

Hi, I would like to know how to find out disk capacity if it is assigned from the storage as a lun. as per below command , I am unable to find out disk capacity. $ bash bash-3.00$ lspv hdisk1 0001579a7fa3c086 None $ lscfg -vl hdisk1 hdisk1 ... (8 Replies)
Discussion started by: manoj.solaris
8 Replies

7. Shell Programming and Scripting

File system capacity meter in shell

HI i need help to show the file system capacity in meter or like the progress bar . OS = Solaris 10 (8 Replies)
Discussion started by: bejo4ever
8 Replies

8. Shell Programming and Scripting

shell script to create disk load

friends , need a shell script to create a disk load. can any one pls guide me with how this can be implemented. Pls provide the concept. from there i will try to design my script. (3 Replies)
Discussion started by: achak01
3 Replies

9. Solaris

Migrate VxVM boot disks to higher capacity disk

Hi, Im getting a downtime of 4 hrs to do porting of bootdisks. Currently, the system is running on Sf4800. 2 internal disk 36G connected to a SE3510 storage. We're getting 72G disks and we want to restore the OS from the current 36G to the 72G disk. System is under veritas volume manager ctrl.... (4 Replies)
Discussion started by: incredible
4 Replies

10. UNIX for Dummies Questions & Answers

Unix disk capacity at 100%

Is there any danger to keeping one of my disks at 100% capacity? (it's a disk just used for read-only files, not system files or anything like that). It's HP-UX if that matters. Thanks! (1 Reply)
Discussion started by: FredSmith
1 Replies
Login or Register to Ask a Question