How to create script with Drush commands? - drupal

Is it possible to create file with sequence of drush commands to be executed?
In particular, I would like to write script, that would download and enable more Drupal modules for example script with these lines (pseudocode).
$modules = {"pathauto", "admin_menu", "i18n"}
drush dl $modules;
drush en $modules;
Is it possible without creating custom drush command?

I have already found solution. I can create a script with Drush API and using drush_invoke command I can call another drush commands.

Related

unix script for initial setup using ssh, newgrp, cleartool setview: how to avoid subshell?

I have following requirements for a project initial setup
need to login to remote server using ssh <servername>
need to change default group using newgrp <grpname>
need to set the clearcase view using cleartool setview <viewname>
change dir to clearcase vobs using cd /vobs/proj/dita
I am trying to write a script which I source when I open a new terminal which does all the above and give me the terminal with required setup.
Now the problem is, 3 out of 4 above commands create a new shell.
Can you help me to achieve this?
Do no use cleartool setview (which does spawn a subshell, as I mentioned before, and as you found out)
Use, as described here, the full path of the view you want to access in your ssh session:
/view/view-tag-name/vobs/some/path
That way, you are sure to remain in the same shell.

Can't open Sqlite on Git Bash

I'm trying to access my sqlite database on my current directory at /c/wamp/www/laravel5 on my local project folder, with windows as my OS. I added the sqlite3 executable on the directory.
The database doesn't seem to open using git bash. When using the default command in windows command prompt it works seamlesly. sqlite3.exe storage/database.sqlite
Tried on Git Bash:
$ ./sqlite3.exe
and
$ ./sqlite3.exe storage/database.sqlite
These didn't work.
The error message is:
bash: sqlite3.exe: command not found
Here's a snapshot:
I'd like to see the database tables and schema using git bash since it has cooler font colors compare with the windows cmd.
Any help would be greatly appreciated.
if you have the same problem I had, then see my question here.
In short, using "winpty" to start sqlite3 worked:
$ winpty sqlite3
Building on the previous answer by #user172431, add the following alias to your .bashrc
alias sqlite3="winpty sqlite3.exe"
This will make the workflow a tad quicker and feel like a ninja rock-star in the process. I use this shortcut via Git Bash

Cant run Shell script in Oozie using Hue

I am trying to run shell script in Oozie using Hue. However it is not running and give exception.
My Shell script file:
#! /bin/bash
hive -e 'desc emptable;'
=======================================
Also added same script file in FILE option in script action.
=======================================
Gives exceptions:
Failing Oozie Launcher, Main class [org.apache.oozie.action.hadoop.ShellMain], exit code [1]
=========================================
I also tried with hive-site file, added in FILE option. but not worked.
Oozie has a specific Hive action, and for a good reason: on a standard Hadoop setup, Hive/Pig/whatever are not installed on the "slave" nodes.
I suggest that you read some documentation on your own.
You should check the logs of the action on the graph of the workflow dashboard page, it should print what really happened.
In the latest Hue, there is even an HiveServer2 action.

Can I use wp-cli to get the Wordpress installation directory?

Can I use wp-cli to return a value for the local Wordpress installation root directory?
Ideally I'd like a wp-cli command like "wp pathname" that returns "user/myname/sites/project_a" when invoked from inside Projects A's installation, and "user/myname/sites/project_b" when invoked inside Project B.
I'm writing a bash script to dump a Wordpress database and do a little post-processing on it. I'm calling on wp-cli to make the dump; I'd also like to use wp-cli to find the pathname for the installation so that I can guarantee than when invoked anywhere in the current installation the dumpfile will always be written to "some/path/to/project_name/dbdumps/". I can't find anything in the documentation about install directory.
wp-cli seems like the right tool for the job because it's Wordpress aware, but I am happy to use some other tool that is capable of discovering my install directory; perhaps a creative and elegant use of the find command, or a way to report the value of Wordpress's FTP_BASE variable?
I ended up doing this with bash, not wp-cli, by using BASH_SOURCE.
There doesn't appear to be a way to do this from within wp-cli itself, but since my script is always running from inside the Wordpress install directory it doesn't matter — I can just find my script's location.

Changing interpreter bash script

Is there any way for changing the interpreter in the middle of a bash script
For instance start with:
#!/bin/bash
Later change to:
#!$drush_location
The reason is because I want to use bash to resolve the location of drush using bash and then pass that var in as an interpreter
You will need to write two scripts and use the first (bash) one to launch the second (drush).
There are other ways to accomplish this, but they are all basically fancy ways of doing the above. For example you could use a here-doc to cram a script contained as a string in your first script into stdin on drush and have it execute that, or even write a temporary file and execute that as a script, but you have to run two processes somehow, you can't change the interpreter on the fly.
Really the thing to do would be to fix your environment so that it can find drush. Then you can use:
#!/usr/bin/env drush
As the hashbang for your drush script. If your system evn can't find it, then fix your search paths until it can!

Resources