Thanks for reading.
I'm having a heck of a time with this cshell script that fires off an hp temperature monitor and rotates logs.
I keep getting
'/opt/temperature/temp.sh: line 22: syntax error: unexpected end of file'
when I try to 'sh /opt/temperature/temp.sh" it
--script begin-------------
#!/bin/csh -f
set tempFile = /tmp/tempfile.log #don't change this
set outfile = /opt/temperature/temperature.log
set sleeptime = 600
set maxNumLines = 24000 # maximum number of lines in the log file
set desNumLines = 18000 # desired number of lines in the log file
while (1 == 1);
do
echo `date` >> ${outfile}
/sbin/hplog -t >> ${outfile}
echo "" >> ${outfile}
sleep ${sleeptime}
set numLines = `wc -l ${outfile}|awk '{print $1}'`
if ( ${numLines} > ${maxNumLines} ); then
tail -${desNumLines} ${outfile} > ${tempFile}
mv ${tempFile} ${outfile}
endif
done
There are several Bourne shell constructs (syntax elements) that are mixed into a csh script.
Here is a version that ran through to the end. I commented out some illegal statements and added correct versions. Some assignments were made innocuous, and some statements were prefixed by echo so that I could run the entire script. Change those back for your system:
#!/bin/csh -f
# set tempFile = /tmp/tempfile.log #don't change this
# set outfile = /opt/temperature/temperature.log
set tempFile = t1
set outfile = t2
# set sleeptime = 600
set sleeptime = 1
set maxNumLines = 24000 # maximum number of lines in the log file
set desNumLines = 18000 # desired number of lines in the log file
# while (1 == 1);
while (1 == 1)
# do
echo `date` >> ${outfile}
# /sbin/hplog -t >> ${outfile}
echo /sbin/hplog -t >> ${outfile}
echo "" >> ${outfile}
sleep ${sleeptime}
set numLines = `wc -l ${outfile}|awk '{print $1}'`
# if ( ${numLines} > ${maxNumLines} ); then
if ( ${numLines} > ${maxNumLines} ) then
tail -${desNumLines} ${outfile} > ${tempFile}
mv ${tempFile} ${outfile}
endif
# done
end
Best wishes ... cheers, drl
---
Standard advice: avoid using csh family for scripting, use Bourne family shells instead.