-sharp!/bin/sh
filesize=`ls -l nohup.out | awk "{ print $5 }"`
echo "`date +%Y-%m-%d_%H:%M:%S` fileSize: $filesize bit" >> clearNohup.log
if [ $filesize -gt 1073741824 ]
then
echo "`date +%Y-%m-%d_%H:%M:%S` $filesize bigger than 1G, we will back up and clear..." >> clearNohup.log
cp -f nohup.out nohup.out.bak
> nohup.out
echo "`date +%Y-%m-%d_%H:%M:%S` file back up and claer over!" >> clearNohup.log
else
echo "`date +%Y-%m-%d_%H:%M:%S` $filesize less than 1G,do nothing!" >> clearNohup.log
fi
the manual execution does not report an error, but it executes normally; it always reports an error during the crontab execution.
the system is centOS6
error:
clearNohup.sh: line 4: [:-gt: unary operator expected
ask for God"s advice!