Friday, June 14, 2013

MX-ONE scripts

Using text files to install an MX-ONE appears to be more complicated than the old MD110 method. However, it can be achieved in the following way. Consider the example below:

#!/bin/bash
license_status -s > /home/user/license.txt

If the above were in a file called lic_export.sh, it could be run sh  lic_export.sh or ./lic_export.sh

That is "linux style" commands, and are thus pretty straightforward. How about MML commands, i.e. commands that require the MDSH (MD Shell)?

Create two files. File1.sh and File2.mx1 (File2 can be .mx1, txt, whatever you want)

File1.sh:

#!/bin/bash
mdsh File2.sh
----------------------------------------------
File2.sh:

roeqi:rou=1,tru=1-1&&1-15,equ=1a-0-10-01;
rodai:dest=0,rou=1;

Running the command sh File1.sh or ./File1.sh will actually run both File1.sh and File2.sh, but File2.sh will be run in the MD shell!

Since you don't want a large file to run out of control, the following can be added to provide some control:

read -n1 -p "Press Enter to continue."

At this point you either press Enter or Ctrl-C if things seem wrong.

Normal bash scripts can be used to provide if statements and while loops so that an entire menu can be presented with choices and exit options.

3 comments:

Unknown said...

Searching the net for a way to execute MML commands inside a bash script (as Aastra`s 90/190 82-ANF 901 was not so obvious for me), I found your blog, and after correcting the typo in File1.sh namely the line:
mdsh File.sh
should be changed to:
mdsh File2.sh
I managed to run the wanted script where the File1.sh contained a single line:
mdsh File2.sh
and the File2.sh file contained both the classical linux type commands as:
ip_extension -p -d all > ipext.log
and the MML type commands like:
niinp:dir=all; > names.log

Running classical linux type command inside mdsh (or MD Shell) works fine, but the md shell is more restrictive, because:

[quote]
mdsh does not support flow control statements like loops, “if” statements “while” statements, pipes and redirection. Another shell should be used if these
features are needed. (bash is recommended.)
[/quote]

Looking for a more elegant way (starting a script just to start an other one is so...) I read again the Aastra doc, and explored
the ability to execute a single MML command instead of a whole file of commands:

[quote]
-c command
Only execute command. The command is executed directly and mdsh is terminated. There is no prompt for commands."
[/quote]

I tried the next line and failed!
mdsh -c niinp:dir=all;

then typed:
mdsh -h
and saw:

[quote]
-c command :
Only execute command. The command is executed directly and mdsh is terminated. There is no prompt for commands.
The -c switch must be the last switch intended for mdsh as everything after -c on the command line is the new command to run.
[/quote]

The help provided by mdsh -h was better then the documentation itself! (see the bold part) but the question why:
mdsh -c niinp:dir=all;
does not work? Remained unanswered.
Searching further I found the page:

http://www.linuxquestions.org/questions/linux-software-2/script-returning-with-error-syntax-error-unexpected-end-of-file-4175474376/

an example of the proper use of the: mdsh -c command
/opt/eri_sn/bin/mdsh -c "ip_extension -p -d all" | grep...
(by the way ip_extension is a simple linux type command, so starting it via mdsh is unnecessary)
I missed the quotes (double quotes). Nor the documentation nor the help provided by the mdsh -h does not mention the quotes!

Finally I rewrote my bash script simply:
...
ip_extension -p -d all > ipext.log
mdsh 'niinp:dir=all;' > names.log
...
and it works as expected!

Unknown said...
This comment has been removed by the author.
Unknown said...

I have some questions regarding scripting for MX-One. Is is possible to contact you directly by email?