How to use Filewatcher to run a shell command

Answered

Hi,

I setup a filewatcher so that when I modify a file, it should clear the var/ directory of my projects, here is the setup that should use bash: http://screencast.com/t/wWDQyJ2EmN however when it triggers it, it gives this output: 

/bin/bash rm -Rf /var/www/html/rental/var/*
/bin/rm: /bin/rm: cannot execute binary file

Process finished with exit code 126

How can I make a filewatcher that does what I want, I don't mind if it doesn't use shell to do this, but you get the idea of what I want to do. 

5 comments
Comment actions Permalink

Hello,

Did you try to execute "/bin/bash rm -Rf /var/www/html/rental/var/*" in command line?

It gives exactly the same error for me.

But "/bin/rm" with arguments "-Rf /var/www/some_dir/*" seem to work fine, just need to check the permissions before.

0
Comment actions Permalink

thanks, that does work in that it runs, however it does not actually clear the contents of the directory. var/cache folder is still there. 

If I run the same thing from terminal it does though, the var/cache folder gets deleted.

output in phpstorm: http://screencast.com/t/sGn5KQKzI

phpstorm is running as root, and I tested separately in a terminal running as root

 

0
Comment actions Permalink

The problem is that '*' can't be expanded when running a watcher, so "/var/www/html/rental/var/*" is unknown - thus nothing is deleted. It's actually the shell that does the * expansion (globbing) and not rm itself, so the command only succeeds when running in a shell.

As a workaround I'd suggest creating a shell script (.sh) with the following content:

/bin/rm -Rf /var/www/some_dir/*

and setting up this .sh as a file watcher (selecting this .sh as a program). This works fine for me

3
Comment actions Permalink

thank you! that worked perfect

0
Comment actions Permalink

Another solution without an shell script is using bash as program with arguments

-c "eval 'rm -rf *'"
0

Please sign in to leave a comment.