0

Background:

I'm using Sass for CSS compilation with Bootstrap 3.

Created a gulp task to trigger the compilation. 'gulp style'

Got tired of executing the gulp style task every time I make a change to the scss file.

Found out about crontab. Created my cron-file.txt to execute a bash file every 30 secs. Answer Courtesy : Running a cron every 30 seconds

* * * * * /bin/bash -l -c "/my/path/autogulp.sh; sleep 30 ; /my/path/autogulp.sh"

autogulp.sh Contents

cd ~
cd /my/path/
gulp style

I tried running the commands manually and they seem to be working fine. Had to change the R/W mode for the cron-file.txt and autogulp.sh. But my objective isn't fulfilled yet. The 'gulp style' isn't working automatically every 30 secs.

I tried routing the std and error output to a file but the contents of the file are always empty.

Community
  • 1
  • 1
  • 1
    This might help: [How to debug a bash script?](http://unix.stackexchange.com/q/155551/74329) – Cyrus Dec 05 '15 at 10:52
  • 1
    It is a pity that the person who voted down didn't leave a comment. This one is too good for a first question here at SO. – sjsam Dec 05 '15 at 11:36

1 Answers1

2

Could be an environment problem. Cron jobs are run with an extremely limited set of environment variables and they won't read your bash_profile or any other startup files. Even PATH may not be set. To verify this, run

$ env -i HOME=$HOME /path/to/script

from your terminal's command line prompt. If this can't run ("command not found"), add

PATH=$(/usr/bin/getconf PATH)

at the start of your script, then try again. Set all variables needed by the script in the script itself.

Jens
  • 69,818
  • 15
  • 125
  • 179