Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a shell script on every request?

Tags:

shell

nginx

I want to run a shell script every time my nginx server receives any HTTP request. Any simple ways to do this?

like image 659
Saswat Padhi Avatar asked Apr 06 '14 07:04

Saswat Padhi


People also ask

What is $1 and $2 in shell script?

$0 is the name of the script itself (script.sh) $1 is the first argument (filename1) $2 is the second argument (dir1)


1 Answers

You can execute a shell script via Lua code from the nginx.conf file to achieve this. You need to have the HttpLuaModule to be able to do this.

Here's an example to do this.

location /my-website {   content_by_lua_block {     os.execute("/bin/myShellScript.sh")   }  } 
like image 163
Chirag Bhatia - chirag64 Avatar answered Sep 19 '22 14:09

Chirag Bhatia - chirag64