Have a relative shebang line

I am writing a rails application and must run scripts with ./script/runner

while i could put

 #!/home/cannon/src/timetracker/script/runner 

upstairs, which will not work in production, where it should be more like

 #!/var/www/loclahost/htdocs/timetracker/script/runner -e=production 

since ./script not in my way and I don't want this to be, how can I enable this setting,

I use cron job to run it in linux box

+4
source share
2 answers

Use env on the shebang line to see things along the way:

 #!/usr/bin/env ./script/runner 
+9
source

Use this at the top of your (ruby) script to re-execute it under local. / script / runner (which then must define Rails so you avoid an infinite loop)

 exec("./script/runner",$0,*ARGV) unless defined?(Rails) 

(So ​​use the regular “ruby” shebang at the top, whether it be #!/usr/bin/ruby or #!/usr/bin/env ruby or some flavor)

0
source

All Articles