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!

Why does this not work in ksh?

Status
Not open for further replies.

twilo202

Programmer
Jan 31, 2002
1
GB
COUNT=`cat ${ALERT_LOG} | wc -l`
#COUNT=100
echo ${COUNT}
tail +${COUNT} ${ORACLE_ALERT}

The error is...

tail: cannot open input

It works fine if I use COUNT=100.

I can only presume that the tail command is interpretted as...

tail +`cat ${ALERT_LOG} | wc -l` ${ALERT_LOG}

although I have another script which does a similar thing and that works...ie...

LLC=`head -1 ${ADMIN_DIR}/${LLC_FILE}`

tail +${LLC} ${LOG_FILE} | grep ORA-

The only difference is that the LLC_FILE is a file with one line holding a number value.
 
If you echo the tail line, you will see why:
Code:
echo tail +${COUNT} ${ORACLE_ALERT}
returns:
tail + <num> <file>
Notice the space between [tt]+[/tt] and [tt]<num>[/tt], which causes your problem.
A better solution is:
Code:
COUNT=$(expr $(wc -l < $ALERT_LOG))
tail +$COUNT $ORACLE_ALERT
Cheers, Neil :cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top