Posts

Get all users in moodle (2.x)

To get all users in moodle using the API(s), you can use the following snippet: #! /user/bin/php <?php define('CLI_SCRIPT', true); require_once('config.php'); // if you call DB inside a function, you'll need: // global $DB; $allusers = $DB->get_records('user'); foreach($allusers as $user) {      echo "User id $user->id is $user->username\n"; } ?>

The power of open in education

Image
Amazing:

Purge Varnish cache

A handy command to purge Varnish cache for a specific host: varnishadm "ban req.http.host == my.host.com"

The best way (until now) to change domain name of a WordPress Multisite

Important Note: If you change the "DOMAIN_CURRENT_SITE" option in your wp-config.php of your multisite, you will not be able to connect to the database (via web and wp-cli) You should use this tool to change the domain name of your multisite: Github repository:  https://github.com/interconnectit/Search-Replace-DB 1. Clone the git repo into your WordPress root: $ git clone https://github.com/interconnectit/Search-Replace-DB 2. Open the browser, go to http://old.multisite.com/Search-Replace-DB/ and start searching and replacing: First search and replace your old url to the new one on all the tables (you can click " dry run " to check first, click " live run " to actually make changes): Old URL: http://old.multisite.com New URL: http://new.multisite.com Then, search and replace old domain to the new one one on all the main wordpress table (wp_sites, wp_blogs,...): Old domain: old.multisite.com New domain: new.multisite.com Af...

How to check if a folder is empty in bash shell

Just use this following script: if find /some/dir/ -maxdepth 0 -empty | read v;  then         echo "Empty dir" fi Or to check not empty: if ! find /some/dir/ -maxdepth 0 -empty | read v; ...

Parsing csv files in shell script

There are many ways to parse csv file in shell script. Here is the one that works well for me: Assuming I have this csv file, mycsv.csv: super,genius cool,awesome ... This script, parse_csv.sh , will parse mycsv.csv: $ nano parse_csv.sh #! /bin/bash IFS=',' while read f1 f2 do         # remove the carriage return character at the end of each line (path column)        newvar= $(echo $f2 | sed -e 's/\r//g')        echo "First column: $f1"        echo "Second column: $newvar" done < $1 $ sudo chmod +x parse_csv.sh $ ./parse_csv.sh mycsv.csv

Passing password to the rsync command with sshpass

In some cases, when writing a bash shell script like running the rsync command multiple times, and you want to avoid entering username and password over and over again, you may find sshpass useful. $ sudo apt-get install sshpass Example script: #! /bin/bash for oldblogid in `cat $1` do         media=/var/www/wp-content/blogs.dir/$oldblogid           echo "=== Checking the existance of $media directory..."                                                                                                if [ -d "$media" ]          then                 echo "    Existed! Copying $media..."           ...