Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unknown Operator in Script - Only when executed by crontab

Status
Not open for further replies.

Stinney

IS-IT--Management
Nov 29, 2004
2,031
US
I have a script that I wrote to check the status of the NIC cards in the system. If I run by calling on the script manually it runs fine. [2thumbsup]

However, I'm getting the following error when the crontab runs it [mad]:

/appbin/maintenance/checknic: test: unknown operator ==

Here is the script:

PATH=/bin:/usr/local/bin:/appbin/maintenance
cestat=`kstat ce | grep link_up | cut -b34-34`
if [ $cestat == 1 ]
then
echo "ce0 UP" | mailx -s "ce0 UP" xxxx@xxxx.com
fi



- Stinney

Favorite all too common vendor responses: "We've never seen this issue before." AND "No one's ever wanted to use it like that before.
 

Stranger things have happened...

When I first wrote the script, for some reason it wasn't working without the double =

I removed it and now it works. Go figure.

- Stinney

Favorite all too common vendor responses: "We've never seen this issue before." AND "No one's ever wanted to use it like that before.
 
When a script runs from 'cron', by default it runs in a Bourne Shell. It is unlikely that when you login, your shell in a Bourne Shell (and hence the different behaviour).

To check what your current shell is, use:
echo $0

To force a script to run in a particular shell, insert the following as the first line, eg:
#!/bin/ksh # for Korn Shell
or
#!/bin/bash # for Bash Shell (Bourne Again)

Different shells use slightly different formats for various commands and some commands are not available is some shells.


I hope that helps.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top