Utilities: moosh

Maintained by Picture of Tomasz Muras 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.
318 sites
30 fans
37 fans

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


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

Comments RSS

Show comments
  • Picture of Tomasz Muras
    Sat, Mar 26, 2016, 4:26 AM
    Chris - most of the commands should just work with Moodle 3.0 - if any does not, report it on github.
    Francis - those are already supported. For example course backup: http://moosh-online.com/commands/#course-backup :
    to backup several coursed based on id, you combine moosh with a bit of bash, for example backup courses with IDs 1,2,3...100:
    for c in $(seq 1 100)
    moosh course-backup $i
  • Picture of Francis Feytout
    Wed, Mar 30, 2016, 5:45 PM
    Thank you Thomas, I was basing myself on the red Xs from your site ( http://moosh-online.com/ci/ ). I will report some issues on github them. Great job so far !
  • Picture of wz z
    Wed, May 25, 2016, 9:30 PM
    I hope it can run on PHP 7.
  • Picture of Tomasz Muras
    Fri, Aug 5, 2016, 3:14 AM
    Yes, it does run with PHP7:

    vagrant@vagrant:~/moosh$ php --version
    PHP 7.0.8-0ubuntu0.16.04.2 (cli) ( NTS )
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.8-0ubuntu0.16.04.2, Copyright (c) 1999-2016, by Zend Technologies

    vagrant@vagrant:~/moosh$ ./moosh.php
    moosh version 0.21
    No command provided, possible commands:
  • Picture of Henry Chung
    Mon, Aug 22, 2016, 8:00 PM
    I'm getting an error when I'm using user-delete:

    PHP Fatal error: Call to undefined function get_sorted_course_formats() in /moodleapp/course/format/lib.php on line 103

    it eventually works after a couple of tries and the user is deleted.
    I've tried upgrading to the latest moosh version but still getting the same error, tried on Moodle 2.8/2.9 and both give same error
  • Picture of sreenu eabyas
    Fri, May 26, 2017, 7:22 PM
    Is it possible backup and restore an activity using moosh?
  • Picture of Tomasz Muras
    Sat, May 27, 2017, 4:38 AM
    At the moment the only backup implemented is backup::TYPE_1COURSE (whole course) in course-backup command.
  • Picture of Bernat Martinez
    Mon, Jul 31, 2017, 7:20 PM
    Is it possible delete multiple users filtering by role? (moosh user-delete)
    Thank's in advance
  • Picture of Jock Coats
    Thu, Nov 30, 2017, 10:40 PM
    Hi Tomasz, this looks amazing. I haven't tried it yet, but looked through the documentation and wondered, can I give it a file for its input. I wish to delete lots and lots of users, and was trying to use "User Upload" with a csv of usernames with the delete flag on but it's running so slowly and wondered if I could use a command line version like this.


    Jock Coats
  • Picture of Tomasz Muras
    Tue, Dec 5, 2017, 1:01 AM
    Hi Jock,

    moosh user-delete does not accept a file as an input (see https://moosh-online.com/commands/#user-delete) 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
  • Picture of Jock Coats
    Tue, Dec 5, 2017, 1:07 AM
    Thanks Tomasz. A colleague also pointed this out to me smile
  • Picture of Cyril Z.
    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.
  • Picture of Henry Chung
    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...
  • Picture of Carlos Sanchez
    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?
1 2
Please login to post comments