Coder Social home page Coder Social logo

routeros-mkdir's Introduction

mkdir for RouterOS 6 and 7

This is a script that creates a $mkdir global variable containing a function. After running the script you will be able to create folders on your Mikrotik device by simply typing $mkdir some/new/path.

  • Easy to use
  • Functionality that was bafflingly left out
  • Should run on Router OS 6.2+ (but only 6.45+ has been tested)

Installation

The Easy Way

Copy the persist_create_mkdir_function.rsc file to your Mikrotik device and then run /import persist_create_mkdir_function.rsc This will create the function, as well as a new scheduler entry that will create the function on startup, ensuring $mkdir is always available to you and your scripts.

The Even Easier Way

Copy and paste the below into your terminal to create the function and persist it using a scheduler startup script.

{
    :local result [/tool fetch \
    url="https://raw.githubusercontent.com/phistrom/routeros-mkdir/master/persist_create_mkdir_function.rsc" \
    as-value output=user];
    :local script [:parse ($result->"data")]
    $script;
}

Usage

On the command line, you can simply type $mkdir any/path/you/want, and the entire folder tree will be created if necessary. If the path already exists, the function quits without doing anything.

In a script, you must have a :global mkdir; declaration at the top of your script in order to use $mkdir.

Example

:global mkdir;
# ensure backups directory exists
$mkdir "disk1/backups";
/system backup save name=disk1/backups/backup;

How it Works

It uses the /tool fetch command as demonstrated here on the Mikrotik official Wiki to download a temporary file to the specified folder. The folders will be created, but the URL given is a non-existent path on localhost so no file is created.

This function runs synchronously meaning it does not return until the folder is created (or an error occurs).

Testing

Only tested on RouterOS 6.44, 6.45, and 7.2. Please open an issue on GitHub if you find this does not work with your particular device/OS.

License

MIT

routeros-mkdir's People

Contributors

phistrom avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.