简体   繁体   English

使用 bash 脚本从 Azure Blob 存储读取 JSON 文件并写回 Blob 存储中的另一个文件

[英]Read JSON file from Azure Blob Storage using bash script and write back to another file in blob storage

I have following JSON file (product.json) stored in Azure Blob storage.我有以下 JSON 文件(product.json)存储在 Azure Blob 存储中。 Is it possible to write bash script to read this file from blob storage make some changes and write back to another blob container.是否可以编写 bash 脚本从 blob 存储读取此文件进行一些更改并写回另一个 blob 容器。 The output file I would like where following changes should occur: output 文件我想在哪里发生以下更改:

Replace "dev" with "qa"将“dev”替换为“qa”

{
    "ds_type": "saas_app",
    "ds_engine": "xxxx",
    "ds_display_name": "xxxx",
    "logo_url": "xxxx/xxxx.png",
    "base_template_path": "xxxx/xxxx/xxxx.cds.json",
    "authentication": {
        "type": "oauth",
        "client_id": "xxxx",
        "client_secret": "xxxx",
        "scope": ["crm.objects.contacts.read", "crm.objects.owners.read"],
        "grant_type": "authorization_code",
        "oauth_base_url": "https://xxxx",
        "oauth_api_url": "https://xxxx",
        "redirect_uri": "https://xxxx-dev.xxxx.com/code",
        "auth_url": "oauth/authorize",
        "token_url": "oauth/v1/token"
    }
}

Please follow the below step to achieve your requirement.请按照以下步骤来实现您的要求。

I am using Ubuntu VM (Version 18.04)我正在使用 Ubuntu VM(版本 18.04)

Step 1: Install AZ CLI module using this below command第 1 步:使用以下命令安装 AZ CLI 模块

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

Step 2: Download Blob file from Storage Account to your local.第 2 步:将 Blob 文件从存储帐户下载到本地。 Below is the picture of container and blob which will be download in local.下面是容器和 blob 的图片,将在本地下载。

在此处输入图像描述

az storage blob download --container-name "your container name" --file "Location of file where you want to copy data" --name "Blob Name" --account-name "Storage Account name" --account-key "Storage Account Access Key"

在此处输入图像描述

Step 3: Check the content of the file using cat command第 3 步:使用 cat 命令检查文件的内容

cat ansuman.json

在此处输入图像描述

Step 4: Run the following command to make changes in your json file第 4 步:运行以下命令以更改 json 文件

replace "dev" "qa" -- package.json

在此处输入图像描述

Step 5: Now to final upload the file in Another Container.第 5 步:现在将文件最终上传到另一个容器中。

az storage blob upload --container-name "your conatiner name where you want to upload" --file "location of local file that is going to upload" --account-name "Storage account name" --account-key "Storage Account Access Key"

在此处输入图像描述

在此处输入图像描述

Reference: https://docs.microsoft.com/en-us/cli/azure/storage/blob?view=azure-cli-latest#az_storage_blob_upload参考: https://docs.microsoft.com/en-us/cli/azure/storage/blob?view=azure-cli-latest#az_storage_blob_upload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM