Operating System - HP-UX
1748246 Members
3504 Online
108760 Solutions
New Discussion юеВ

Re: shell script question ..... regarding file size test

 
SOLVED
Go to solution
Daniel Dumont_1
Advisor

shell script question ..... regarding file size test

I am trying to test the size(greater than zero) of a file in "c" shell.(HPUX11)
If it is greater than zero bytes .... I want to send and email to abc ..... if it is zero bytes I want to email def.
Here is the test I am doing and I am getting a "if: Badly formed number." error and the script halts.
Can anyone tell me where I am going wrong?

if (-s /directsm/errors.txt) then
elm -s EDI_ERROR abc@abc.com < /directsm/errors.txt
else
elm -s $SHIPPERFILE def@abc.com < $TDFFILE
endif
Will assign points for solutions!!
5 REPLIES 5
Kent Ostby
Honored Contributor

Re: shell script question ..... regarding file size test

I think it needs to be brackets and spaces so:

if [ -s /directsm/errors.txt ]
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Dave Olker
HPE Pro

Re: shell script question ..... regarding file size test

Hi Daniel,

Try:

if [ -s /directsm/errors.txt ]
then
...
fi

Regards,

Dave
I work for HPE

[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
Rodney Hills
Honored Contributor
Solution

Re: shell script question ..... regarding file size test

csh is not as robust as ksh or posix sh. Is their a reason you are doing this in csh?

The "-s" is not a valid csh selection. You could use "-z" to test for zero instead.

if ( -z /directsm/errors.txt ) then
elm ...
else
elm ...
endif

HTH

-- Rod Hills
There be dragons...
Daniel Dumont_1
Advisor

Re: shell script question ..... regarding file size test

Thanks Rodney ..... that solved the problem.
I was getting very strange errors trying to use the -s with the c shell.
Can I ask you where you found out that the -s was not valid with the c shell?
Will assign points for solutions!!
Rodney Hills
Honored Contributor

Re: shell script question ..... regarding file size test

Do a "man csh" and look for section on "expressions". It lists what is allowed in a csh expresssion.

HTH

-- Rod Hills
There be dragons...