0

I am writing a script to write the output of df -g to a text file once a week. here's my script, I think it should work, but whenever I try and run it as root by typing ./check_space.sh I get the following error: ./check_space.sh: line 13: syntax error near unexpected token done' ./check_space.sh: line 13:done'

#!/bin/bash
#this script will run every week to grab a df -g and output it to a file.
#times to sleep
        #10080 = 1 week

#date command
NOW=$(date +"%m.%d.%y")

while true, do
df -g > /sds/app/force/custom/dumplogs/harddisk/$NOW.log

#sleep 10080
done

originally I was thinking of running this script in a screen session, that is why the Sleep is in there, but I quickly decided that it would be better to run it as a cron once a week.

vitr
  • 6,766
  • 8
  • 30
  • 50

1 Answers1

1

The problem is caused by the comma after the true. The correct syntax is with a semicolon: while true; do. But you don't need the while loop in the first place. Something like the following will suffice:

#!/bin/bash

NOW=$(date +"%m.%d.%y")
df -g > /sds/app/force/custom/dumplogs/harddisk/$NOW.log

May I also suggest that you use %Y-%m-%d as the date format, to make it easier to sort by date.

redneb
  • 21,794
  • 6
  • 42
  • 54