FuelPHP - Oil batch processing using bash
I've been thinking about some slightly advanced usage of the Oil utility inside the Fuel framework for my new project. I don't like typing the "scripts" one by one in to the terminal because, I'm too lazy for that and moreover, after typing 5 and more commands, I almost always find myself lost in the bash history. Fortunately, there is really simple solution this (for *nix environments).
First of all, I've created a text file, let's call it migrate_01.txt, containing let's say some code from documentation about oil the migrations:
generate migration create_users name:text email:string[50] password:string[125] generate migration rename_table_users_to_accounts generate migration add_bio_to_accounts bio:text generate migration rename_field_name_to_username generate migration drop_accounts
As you see, it's super simple - one oil command per line. Now, for running this in one step, all you need to do is run:
cat migrate_01.txt | xargs -L1 -P1 oil
... and it's done.
The first parameter -L basically means that command oil will be called on every line of the file, the second, -P sets the limit of simultaneous invocations of the script. That means, one oil command will run at the time. Limiting the simultaneous processes maybe isn't necessary, it just feels safer, at least for me.
