Use n98-magerun Script Repository

Published by Christian Münch on

Since some releases we support script. Scripts are like batch files which can be executed and reused in all your local Magento installations. For everyone who is not fimilar with n98-magerun script I gave a little instruction how the scripts can be created.

My first n98-magerun script

Scripts can do three things…

  1. Register variables
  2. Run shell commands
  3. Run n98-magerun commands

    One of the big advantages is that Magento is only initialized once. If you have used n98-magerun in your deployment or setup script you will see
    that the script command can boost the speed of script execution a lot.

The script command offers you some pre-defined variables which you can use in your scripts:

${magento.root} -> Magento Root-Folder
${magento.version} -> Magento Version i.e.
${magento.edition} -> Magento Edition -> Community or Enterprise
${magerun.version} -> Magerun version i.e. 1.66.0
${php.version} -> PHP Version
${script.file} -> Current script file path
${script.dir} -> Current script file dir

The most important variable is ${magento.root}.

Here is a complete script example:

# First comment line is used in script repo list command to show description

config:set "web/cookie/cookie_domain"
config:set "web/secure/base_url"
config:set "web/unsecure/base_url"

# Run a shell script with "!" as first char
! ls -l

# Register your own variable (only key = value currently supported)

# Let magerun ask for variable value - add a question mark

! echo ${my.var}

# Use resolved variables from n98-magerun in shell commands
! ls -l ${magento.root}/code/local

n98-magerun Script Repository

You can organize your scripts in a repository. Simply place a script in folder /usr/local/share/n98-magerun/scripts or in your home dir in folder /.n98-magerun/scripts.

Scripts must have the file extension .magerun.

After that you can list all scripts with the script:repo:list command. The first line of the script can contain a comment (line prefixed with #) which will be displayed as description.

$ n98-magerun.phar script:repo:list

If you want to execute a script from repository this can be done by script:repo:run command.

$ n98-magerun.phar script:repo:run [script]

Script argument is optional. If you don’t specify any you can select one from a list.

See it in action

Categories: Magerun

1 Comment

Using Magerun modules in your projects – thongquach · May 19, 2017 at 04:48

[…] first two locations are described on the Use n98-magerun Script Repository page. Both locations are specific to your local machine and are well documented. The third option […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.