0

I have a post-commit hook that works, but for some reason the following line of code is not working properly. It creates my test file regardless of a fail.

!#/bin/sh

# force a failure
ifconfig -z 1>/dev/null 2>&1

if [ $? -ne 0 ]
then
   touch ~/Desktop/fail.txt
fi

The fail.txt file is created with or without that -z. However, if I run this same code without executing via my post-commit hook, it works as it should.

Any suggestions?

nullByteMe
  • 6,141
  • 13
  • 62
  • 99

1 Answers1

1

Hook scripts execute in an empty environment, including an empty or severely limited PATH. As a result, your script most likely can't find/can't execute ifconfig.

Specify full paths to everything within your hook scripts.

alroc
  • 27,574
  • 6
  • 51
  • 97
  • Interestingly, it is able to determine what `~/` is and `touch` since the file is successfully created. I'm going to try and add the full path to `ifconfig` and see what happens. – nullByteMe Mar 06 '14 at 14:17
  • Note that I did say "severely limited `PATH`" - `~` may be part of that limited environment, and `touch` may be in that `PATH`. – alroc Mar 06 '14 at 14:19
  • Your suggestions worked! Thanks for the quick answer. – nullByteMe Mar 06 '14 at 14:20