Maintained by Tomasz Muras
Moosh stands for MOOdle SHell. It is a commandline tool that will allow you to perform most common Moodle tasks. It's inspired by Drush - a similar tool for Drupal.
Latest release:
72 fans
Current versions available: 2

Moosh is a tool that exposes some common Moodle functionality to the commandline.

You install moosh outside of the Moodle directory, it can be anywhere really. Then simply make moosh.php (or symlink named like moosh) available somewhere in $PATH.

To run moosh, change the directory into your installed Moodle's instance and run one of the commands. To get the list of all available commands only run moosh.php (or just moosh if you've symlinked it like this) or read the documentation and examples.

Moosh is meant to work nicely with Linux features like bash/zsh expansion. For example, to create 10 users, you just type:

% moosh user-create username{1..10}



Screenshot #0


Tomasz Muras (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Tue, Dec 5, 2017, 1:01 AM
    Hi Jock,

    moosh user-delete does not accept a file as an input (see but you can use a power of Linux command line and simply do something like:
    cat file_with_user_names.txt | xargs moosh user-delete
  • Tue, Dec 5, 2017, 1:07 AM
    Thanks Tomasz. A colleague also pointed this out to me smile
  • Mon, Apr 9, 2018, 7:29 PM

    Unfortunately, I was not able to run Moosh. Some information is missing on the offical Moodle's web page and on the official website. You may miss potential users and you seem to have worked hard to realise this great tool. Too bad.

    A video explaning how to install it and how to link it to moodle in local (and in production) would be great. Is it uesable with a Moodle which is not hosted in local ? I mean a test website or even a production website ? If there was some more information I would be interested in making a video tutorial.

    I really hope to get information from you and to be able to use it soon.

    Thank you in advance.
  • Thu, Aug 2, 2018, 6:25 PM
    I'm getting the following error when using block-add (moosh v0.26) on Moodle3.5+, mysql 5.7.19 and 5.7.23

    Default exception handler: Error writing to database Debug: Field 'timecreated' doesn't have a default value
    INSERT INTO mdl_block_instances (blockname,parentcontextid,showinsubcontexts,pagetypepattern,subpagepattern,defaultregion,defaultweight,configdata) VALUES(?,?,?,?,?,?,?,?)
    [array (
    0 => 'gsb',
    1 => 343147,
    2 => 1,
    3 => 'course-view-*',
    4 => NULL,
    5 => 'Right',
    6 => '10',
    7 => '',
    Error code: dmlwriteexception
    * line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown
    * line 1329 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
    * line 1375 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
    * line 98 of /usr/share/moosh/Moosh/Command/Moodle23/Block/BlockAdd.php: call to mysqli_native_moodle_database->insert_record()
    * line 59 of /usr/share/moosh/Moosh/Command/Moodle23/Block/BlockAdd.php: call to Moosh\Command\Moodle23\Block\BlockAdd->blockAdd()
    * line 291 of /usr/bin/moosh: call to Moosh\Command\Moodle23\Block\BlockAdd->execute()

    !!! Error writing to database !!
  • Wazza
    Fri, Aug 17, 2018, 4:52 PM
    This seems a very good plugin to use, however... I'm running in some problems. Is it possible to make this a 'real' Moodle-plugin, and with that I mean a plugin that can be installed and accessed from within Moodle?

    As an example I would like to refer to adminer, a tool to get direct access to the database. The plugin installs and runs within Moodle, accessible from the web.

    The problem is that many don't have shell access (or even FTP access) to the server Moodle is running on. That way, you can't use this plugin at all...
  • Tue, Feb 12, 2019, 6:33 PM
    Thank you so much. Very useful.
    I am going to use it to integrate a woocommerce store with the moodel courses.
    One question, is it possible to specify the end date of enrollment in a course?
  • Wed, May 22, 2019, 4:56 PM
    Thank you so much for this very useful tool (reducing time consuming reading API).

    I'm using moosh for a while with great satisfaction (backup automation is done with it and works very well).

    I encounter a problem since "surely upgrade version 3.6.3" with user creation.
    Here is the message I got every time a user is created with moosh (in fact user is created with username good, firstname and lastname the same but message stop the script : I could catch the error but I would like to avoid the error, better isn't-it ?).

    I use moosh 0.29 and Moodle 3.6.3+ (Build: 20190418)

    Here is the error (and the command sent) :

    /home/www/moosh/moosh.php -p=/home/www/moodle/htdocs -n user-create --city "Bruxelles" --country "BE" 19ag0022
    Default exception handler: Exception : Call to undefined method cachestore_dummy::find_by_prefix() Debug:
    Error code: generalexceptionmessage
    * line 1796 of /cache/classes/loaders.php: Error thrown
    * line 131 of /user/lib.php: call to cache_session->purge_current_user()
    * line 80 of /home/www/moosh/Moosh/Command/Moodle23/User/UserCreate.php: call to user_create_user()
    * line 297 of /home/www/moosh/moosh.php: call to Moosh\Command\Moodle23\User\UserCreate->execute()

    Thanks for help (I'm gonna catch the error waiting for soluce).
  • Wed, Jun 19, 2019, 7:23 PM
    Is there any command to set the "letters(percentage)" grader report settings in a single go. Like we set it by visiting single course at a time.
  • Fri, Aug 7, 2020, 12:09 AM
    Hi Tomasz, any chance of getting a Moodle 3.9 compatible version soon? smile
  • Fri, Aug 7, 2020, 2:30 PM
    Hi Michael. The current version (the core and most of the commands) work with 3.9 already. If you notice any problems, please report in the tracker.
  • Fri, Dec 11, 2020, 5:28 PM
    The website ( seems to have expired and now shows what looks like a placeholder site.
  • Fri, Dec 11, 2020, 5:40 PM
    Fixed, thanks for letting me know Edward.
  • Mon, Dec 14, 2020, 10:23 PM
    Hi Tomasz
    I need to copy a questionnaire in multiple courses. Through moosh I use the following instruction.
    moosh -n activity-add --name "Enquesta Avaluació Assignatura" --section 1 --idnumber "45766" --name "Enquesta Àlex" questionnaire 3735 but this copy the questionnaire without the questions.
    i see the documentation and i don't know we happend.
  • Tue, Mar 9, 2021, 8:31 PM
    Hi Tomasz

    Firstly, let me say what an excellent tool moosh is. We have used it extensively in v3.9.1, and it has been invaluable.

    Is there going to be a 3.10.2 version soon? We are testing an upgrade annd when I run moosh, I get this error message

    Fatal error: Uncaught Exception: Unable to determine branch version from 'C:\inetpub\mapleroot/version.php' in C:\Users\bhaji\moosh\includes\functions.php:147
    Stack trace:
    #0 C:\Users\bhaji\moosh\moosh.php(74): moosh_moodle_version()
    #1 {main}
    thrown in C:\Users\bhaji\moosh\includes\functions.php on line 147

    We're on Windows (sorry about that) running php v7.4
  • Ricardo Caiado
    Tue, Mar 15, 2022, 5:04 PM

    "sudo -u www-data moosh db-stats" gives me:

    "Default exception handler: Erro ao ler a base de dados Debug: ERROR: syntax error at or near "'table'"
    LINE 1: SELECT table_name AS 'table',
    SELECT table_name AS 'table',
    ROUND(((data_length + index_length))) AS 'size'
    FROM information_schema.TABLES
    WHERE table_schema = 'db_ava_nead'
    ORDER BY (data_length + index_length) DESC
    -- line 25 of /usr/share/moosh/Moosh/Command/Moodle39/Report/DbStats.php: call to pgsql_native_moodle_database->get_records_sql()
    [array (
    Error code: dmlreadexception
    * line 486 of /lib/dml/moodle_database.php: dml_read_exception thrown
    * line 329 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end()
    * line 977 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
    * line 25 of /usr/share/moosh/Moosh/Command/Moodle39/Report/DbStats.php: call to pgsql_native_moodle_database->get_records_sql()
    * line 361 of /usr/bin/moosh: call to Moosh\Command\Moodle39\Report\DbStats->execute()

    !!! Erro ao ler a base de dados !!!"

    Moodle v3.11.4+"
    PostgreSQL 12
    PHP 7.4
    Ubuntu 20.04

1 2 3
Please login to post comments