• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Problem with Bash scripting

Pegun

Golden Member
I'm trying to take a file which is a weblog and output certain statistics about it. The input (first line) is 23/Dec/2007:15:08:08

I use the following code to get just the date and compare it to the final date in the file:

varstartdate=$(cut -f4 -d " " "access_log.1998-12" | head -1 | sed -e 's/\[/\ /g' -e 's/\:/\ /g' -e 's/\//\ /g' | cut -f2 -d " ")
varenddate=$(cut -f4 -d " " "access_log.1998-12" | tail -1 | sed -e 's/\[/\ /g' -e 's/\:/\ /g' -e 's/\//\ /g' | cut -f2 -d " ")
if [$varstartdate > $varenddate]
then $varenddate=$varenddate + 30
fi

#vartotaldays=$varenddate - $varstartdate
#echo "Total number of days = " $vartotaldays

I keep getting a "[23 command not found" error. Because I'm not used to bash scripting I have no idea what the problem is. Can anyone help?
 
Thanks, apparently in contrast to the other languages I'm used to using theres a difference between if [con1 -gt cond2] and if [ cond1 -gt cond2 ]. The spacing between brackets and conditions makes all the difference
 
Back
Top