如何将我的 bash 脚本结果加载到特定位置
How to load my bash script result to a specific location
如何将我的 bash 脚本生成的输出加载到 gcs 位置
就像我的 bash 命令是:
回声“你好世界”
我希望此输出 (hello world) 显示在 gcs 中的某个位置。
如何在bash中写定位命令?任何更新将不胜感激?提前致谢
首先,你应该在你的机器上install Cloud SDK instructions in order to use the cp command form gsutil tool执行脚本运行。
- Cloud SDK requires Python; supported versions are Python 3 (preferred, 3.5 to 3.8) and Python 2 (2.7.9 or higher)
- Run one of the following:
Linux 64-bit archive file from your command-line, run:
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-362.0.0-linux-x86_64.tar.gz
For the 32-bit archive file, run:
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-362.0.0-linux-x86.tar.gz
Depending on your setup, you can choose other installation methods
- Extract the contents of the file to any location on your file system (preferably your Home directory). If you would like to replace an existing installation, remove the existing
google-cloud-sdk
directory and extract the archive to the same location.
- Run gcloud init to initialize the SDK:
./google-cloud-sdk/bin/gcloud init
安装 Cloud SDK 后,您应该create a bucket to upload包含脚本生成的输出的文件。
Use the gsutil mb
command and a unique name to create a bucket:
gsutil mb -b on -l us-east1 gs://my-awesome-bucket/
This uses a bucket named "my-awesome-bucket". You must choose your own, globally-unique, bucket name.
然后您可以将输出重定向到本地文件并上传到 Google 云存储,如下所示:
#!/bin/bash
TIMESTAMP=$(date +'%s')
BUCKET="my-awesome-bucket"
echo "Hello world!" > "logfile.$TIMESTAMP.log"
gsutil cp logfile.$TIMESTAMP.log gs://$BUCKET/logfile.$TIMESTAMP.log
如何将我的 bash 脚本生成的输出加载到 gcs 位置
就像我的 bash 命令是:
回声“你好世界”
我希望此输出 (hello world) 显示在 gcs 中的某个位置。
如何在bash中写定位命令?任何更新将不胜感激?提前致谢
首先,你应该在你的机器上install Cloud SDK instructions in order to use the cp command form gsutil tool执行脚本运行。
- Cloud SDK requires Python; supported versions are Python 3 (preferred, 3.5 to 3.8) and Python 2 (2.7.9 or higher)
- Run one of the following:
Linux 64-bit archive file from your command-line, run:
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-362.0.0-linux-x86_64.tar.gz
For the 32-bit archive file, run:
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-362.0.0-linux-x86.tar.gz
Depending on your setup, you can choose other installation methods
- Extract the contents of the file to any location on your file system (preferably your Home directory). If you would like to replace an existing installation, remove the existing
google-cloud-sdk
directory and extract the archive to the same location.- Run gcloud init to initialize the SDK:
./google-cloud-sdk/bin/gcloud init
安装 Cloud SDK 后,您应该create a bucket to upload包含脚本生成的输出的文件。
Use the
gsutil mb
command and a unique name to create a bucket:
gsutil mb -b on -l us-east1 gs://my-awesome-bucket/
This uses a bucket named "my-awesome-bucket". You must choose your own, globally-unique, bucket name.
然后您可以将输出重定向到本地文件并上传到 Google 云存储,如下所示:
#!/bin/bash
TIMESTAMP=$(date +'%s')
BUCKET="my-awesome-bucket"
echo "Hello world!" > "logfile.$TIMESTAMP.log"
gsutil cp logfile.$TIMESTAMP.log gs://$BUCKET/logfile.$TIMESTAMP.log