0

Could anyone point out what's wrong with the below line from a bash script I'm using?

if [ "$(( $(date +"%s")-$(stat -c "%Y" $SENDDIR/$NIGHTLY_FILE) ))" -gt "3600" ]; then

I receive the error noted in the subject line.

I had copied the script from one server to another thinking that it should work but alas, no.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
PeteJ
  • 1
  • 3
  • 2
    wrap that line with `set -vx` above and `set +vx` below so you can see how the variables are being expanded. Then it should be very easy to see where the problem is with you math values. Good luck. – shellter Dec 09 '13 at 02:12
  • Hi @shellter, Thanks for the input. With that enabled this is the output: date +"%s") -$(stat -c "%Y" $SENDDIR/$NIGHTLY_FILE) date +"%s" ++ date +%s stat -c "%Y" $SENDDIR/$NIGHTLY_FILE) stat -c "%Y" $SENDDIR/$NIGHTLY_FILE ++ stat -c %Y /senddir/nightly_file.xml stat: cannot stat /senddir/nightly_file.xml': No such file or directory ./file.sh: line 75: 1386560712 - : syntax error: operand expected (error token is "- ") I've looked it over but am not sure how to interpret the output. edit: Apologies about the lack of formatting. – PeteJ Dec 09 '13 at 03:52
  • 2
    Does `/senddir/nightly_file.xml` exist? The error seems to indicate otherwise. – Michael Dec 09 '13 at 04:41
  • Hi Michael. Bingo. The rudimentary script was fine. A particular directory the script relies on was not where it should have been on the new server. Thank you both for the input! – PeteJ Dec 09 '13 at 22:48
  • possible duplicate of [Syntax error: operand expected (error token is "+")](http://stackoverflow.com/questions/20176640/syntax-error-operand-expected-error-token-is) – Agostino Mar 03 '14 at 14:24

0 Answers0