Hi guys,
I am not a programmer, but from time to time I need to "bash" scripts for my system. And I need some help with this one.
I have a program which continuously writes info to log files. I want to create a script which would check if the program is running by comparing current log file size with the log size recorded earlier (if sizes are equal, the program isn't running as it is supposed to). This is the script I came up with:
Code:
#!/bin/bash
#I try to store the size of the file into $FILENAME
FILENAME=/tmp/sz.txt
#this is the log file I'm checking the size of
LOGNM=/tmp/GJM-cdrcap.log
#simple IF to check if sz.txt exists
if test -r "$FILENAME"; then
echo "file exists"
else touch "$FILENAME"
echo "file created"
fi
#current size of the log file
NEWSZ=$(stat -c%s "$LOGNM")
#old log file size from sz.txt file
OLDSZ=($(grep -ne "[0-9]\+" $FILENAME))
if ["$NEWSZ" != "$OLDSZ"]; then
echo "old size *$OLDSZ*"
echo "new size *$NEWSZ*"
echo "program is fine. files are not equal"
else
echo "old size *$OLDSZ*"
echo "new size *$NEWSZ*"
echo "program stalled. files are equal"
fi
When I run it I get:
Code:
# ./re.sh
file exists
./re.sh: line 16: [134127: command not found
old size *128698*
new size *134127*
program stalled. files are equal
Can't figure out what's going on in here. First of all, it returns an error. Also, files are not equal...