help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] run bundler command from shell script


From: Greg Wooledge
Subject: Re: [Help-bash] run bundler command from shell script
Date: Wed, 2 Aug 2017 08:28:46 -0400
User-agent: NeoMutt/20170113 (1.7.2)

On Wed, Aug 02, 2017 at 11:42:49AM +0000, Arup Rakshit wrote:
> Right now I was following this steps:
> 
> sh deploy-frontend-staging.sh
> cd ../backend/ruby
> bundle exec mina passenger_restart TO=staging

Do you run all of this from an interactive terminal?  The *same* terminal,
one right after the other?

> It works as expected. But I thought to add the last 2 lines in the shell 
> script itself, and it is like below:
> 
> ssh address@hidden "rm -rf /home/application/shared/public/inspection_tool/*"
> scp -r dist/* address@hidden:application/shared/public/inspection_tool/
> cd ../backend/ruby
> bundle exec mina passenger_restart TO=staging

Your script is missing its shebang (#!/bin/sh or similar).

You must check the exit status of cd before proceeding.  If the cd
fails, but you carry on, working in the wrong directory, bad things
could happen.

cd ../backend/ruby || exit

> Now when I run the script, I get below error:
> 
> deploy-frontend-staging.sh: line 4: bundle: command not found
> 
> What I need to fix in this script?

I've mentioned two already.

Next up: your cd command is using a relative path, so it changes to a
directory relative to wherever you are sitting when you run the script,
or wherever the script has taken you if there is more code in the script
that you simply have not shown.

Are you still running the script in an interactive terminal shell?
Are you sitting in the same directory that you were when you ran the
commands manually?

Perhaps you should consider changing the cd to an absolute path, so
that it won't matter where you are sitting when you run the script.

Finally: where is "bundle" supposed to be?  If you run "type bundle"
from your interactive shell, what do you get?

If it's a function or alias, then you need to import that same function
or alias into the script.  (And if it's an alias, either convert it
to a function, or turn on aliases within the script, since aliases are
*off* by default in scripts.)

If it's ./bundle then your interactive shell has included . in PATH,
which is a very bad practice.  If this is the case, then change the
script to run ./bundle instead of bundle.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]