Re: shell script question ..... regarding file size test (196 Views)
Reply
Advisor
Daniel Dumont_1
Posts: 23
Registered: ‎12-16-2003
Message 1 of 6 (196 Views)
Accepted Solution

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!!
Honored Contributor
Kent Ostby
Posts: 1,836
Registered: ‎09-26-2000
Message 2 of 6 (196 Views)

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"
HP Pro
Dave Olker
Posts: 1,427
Registered: ‎10-10-2002
Message 3 of 6 (196 Views)

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

Hi Daniel,

Try:

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

Regards,

Dave
Honored Contributor
Rodney Hills
Posts: 1,679
Registered: ‎09-09-1996
Message 4 of 6 (196 Views)

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...
Advisor
Daniel Dumont_1
Posts: 23
Registered: ‎12-16-2003
Message 5 of 6 (196 Views)

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!!
Honored Contributor
Rodney Hills
Posts: 1,679
Registered: ‎09-09-1996
Message 6 of 6 (196 Views)

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...
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.