Install .NET Core in Linux using Azure Batch Start Task

  • Follow this link to create a shell script and name it as for ex- dotnetcoreinstall.sh.

     

  • Upload the script dotnetcoreinstall.sh to the storage account from where start task will be downloaded in the Linux VM.

     

  • Create a BatchPool consisting of required Linux VM distro and edit the Start Task as shown below. I have used BatchLabs tool to simulate the scenario, same thing holds true in case the pool is created from portal as well.

    Blob source : https://batchpratyaystorage.blob.core.windows.net/batchcontainer/dotnetcoreinstall.sh - This represents the actual URL of the blob (i.e the script).
    File path : /mnt/batch/tasks/startup/wd-This represents the local path in Linux VM where the script will be downloaded from storage account.

     

    Create Azure Batch Start Task

  • The above two steps works as expected when you have created the script from a Linux environment. The same steps fails with the below error when you create the script in windows environment and upload to storage account.

     

    (--install):rocessing archive packages-microsoft-prod.deb

    cannot access archive: No such file or directory

    Errors were encountered while processing:

    packages-microsoft-prod.deb

    ] is not understood in combination with the other options.

    ] is not understood in combination with the other options.

    Reading package lists... Done

    Building dependency tree

    Reading state information... Done

    E: Unable to locate package dotnet-sdk-2.1.200

    E: Couldn't find any package by glob 'dotnet-sdk-2.1.200'

    E: Couldn't find any package by regex 'dotnet-sdk-2.1.200'

     

    The reason being, the script in different environments (Windows / Linux) are created in different formats. The way you can figure out that is by running file command in Linux bash shell. Unix systems use a single character -- the linefeed -- and Windows systems use both a carriage return and a linefeed (often referred to as "CRLF") to terminate lines in text files.

    Refer : <https://www.networkworld.com/article/3107972/linux/windows-vs-unix-those-pesky-line-terminators.html>

    $ file dotnetcoreinstall.sh                                                                           ////  Script created in Windows and uploaded to storage account
    dotnetcoreinstall.sh: ASCII text, with CRLF line terminators

    $ file dotnetcoreinstall.sh                                                             ////  Script created in Linux and uploaded to storage account
    dotnetcoreinstall.sh: ASCII text

     

  • Hence to prevent the above file format mismatch, we can follow either of the below steps:

     

    • Create the script in a different Ubuntu box and upload to the script to the storage explorer using storage explorer for linux.

     

    • If you don’t have storage explorer in linux environment, get the script from the VM created in the previous step to your windows box using the below Putty command. Putty tool comes with the below executable pscp.exe

Get the script from the VM using pscp.exe

Once you have retrieved the file from Linux to Windows, upload the file to the storage account as it is.

 

    • You can also automate the process of converting files from Windows (DOS) to Unix format to save yourself a little trouble using the command.

       

      $ dos2unix dotnetcoreinstall.sh

       

        However to execute the above command you need to first install the package dos2unix using the command : sudo apt-get install dos2unix