Misha Moroshko
Misha Moroshko

Reputation: 171321

Rails: How to run "rake" commands using Bash script?

I created reset_db.sh (with chmod +x) with the following content:

#!/bin/bash
echo "*** Deleting the database ***"
rake db:drop --trace
echo "*** Creating the database ***"
rake db:create --trace
echo "*** Migrating the database ***"
rake db:migrate --trace
echo "*** Seeding the database ***"
rake db:seed --trace
echo "*** Done! ***"

However, when I run:

bash reset_db.sh

I see:

*** Deleting the database ***
*** Creating the database ***
*** Migrating the database ***
*** Seeding the database ***
*** Done! ***

but the rake commands were not executed.

Any ideas why ?

Bonus question:

What should I do in order to be able to run reset_db.sh rather than bash reset_db.sh ?

Upvotes: 1

Views: 2650

Answers (2)

lebreeze
lebreeze

Reputation: 5134

Add set -x at the top of your bash script for more verbose output.

#!/bin/bash

set -x

echo "*** Deleting the database ***"
rake db:drop --trace
echo "*** Creating the database ***"
rake db:create --trace
echo "*** Migrating the database ***"
rake db:migrate --trace
echo "*** Seeding the database ***"
rake db:seed --trace
echo "*** Done! ***"

Does that give you any further information?

Upvotes: 5

Matteo Alessani
Matteo Alessani

Reputation: 10412

to run the command you need to type:

./reset_db.sh

Regarding the rake command, are you in the folder where the rake should be launched?

Upvotes: 2

Related Questions