Add a new script

To use scripts with Smart Tools, you need to add your scripts to your account. To do this, Smart Tools provides a code editor. You can enter your script by hand, copy and paste script content, or drag and drop your script file into the code editor. The code editor provides basic editing features such as syntax highlighting and check, key bindings, drag and drop, and cut, copy, and paste.

  1. From the home page, click Smart Build.
  2. On the Library page, click New Script.
  3. Enter a script name and file extension.

    For example: bash, sh, ps1, perl, py, and so on.

  4. (Optional) Enter tags and description.

    Tags enable you to quickly search and retrieve your scripts from the existing scripts. To insert a tag, enter the tag and press Enter. You can enter a description that best describes the purpose of your script.

  5. Click Next
  6. Enter your script in the code editor. The following is a sample bash script:

    #!/bin/bash

    dbrootpwd=$1
    dbname=$2
    dbpasswd=$3
    dbuser=$4

    yum -y install mysql mysql-server mysql-devel mysql-libs
    service mysqld start

    mysqladmin -u root password $dbrootpwd

    cat << EOF > /tmp/mysql_setup.sql
    CREATE DATABASE $dbname;
    CREATE USER '$dbuser'@'localhost' IDENTIFIED BY '$dbpasswd';
    GRANT ALL ON $dbname.* TO '$dbuser'@'localhost' WITH GRANT OPTION;
    CREATE USER '$dbuser'@'%' IDENTIFIED BY '$dbpasswd';
    GRANT ALL ON $dbname.* TO '$dbuser'@'%' WITH GRANT OPTION;
    FLUSH PRIVILEGES;


    Note:
    Include appropriate error handlers in your script code for Smart Tools to interpret script failures. For example, you can program your script to exit with an error message in case of a script failure.

  7. Ensure that the Line Ending option is set to Auto. You can set this option to Windows or Unix depending on the operating system that will run your script. The default setting is Auto. Line Ending is a special character or a sequence of characters that signifies the end of a line in your script. Scripts or text files created in Windows have different line endings against the files created in Unix/Linux. If you transfer scripts between Windows and Unix machines, ensure that the line endings are translated properly.

  8. Click Next.
  9. (Optional) Specify script parameters and click Next
    Note: Use only positional parameters (Example: $0, $1, $2). Do not use obvious parametes (Example: $foo).

    You can specify default values for script parameters. Values defined for parameters are saved and passed to the script at runtime. For example, consider the parameters used in the above sample bash script. You can assign values to the parameters defined in the bash script as follows:

    script-parameters.png

    Other examples are, if you are adding an installer script, you might specify a parameter called "mode" with default value "install." When you run the script, the value "install" is passed to the script and the installation is performed. You might also define a parameter called "location" with a default value of "/opt/packages" or another destination. You can also specify parameter values for ports, passwords, usernames, and so on. In some cases, if you plan to share a script, you can leave parameter values unspecified and let the users specify values based the requirements. 

  10. (Optional) Click Upload file(s) to attach files that support your script.

  11. You can select a single file or multiples files to upload.
  12. Click Finish.

The newly added script appears in the list on the Library page.

0 Comments