When creating a CVM, you can configure an instance by specifying custom data. During the first launch of the CVM, the custom data will be passed into the CVM in text format and be executed. If you purchase multiple CVMs at a time, all CVMs will execute the custom data upon their first launch.
This article describes how to pass a Shell script when launching a Linux CVM for the first time.
root
. Therefore, the sudo
command is not required in the script. The root
user can access all the files you created. If you need to grant other users with the access permission, modify the permission in the script.#!
and the path to the interpreter reading the script (usually /bin/bash
).Run the following command to create a Shell script named “script_text.sh”.
vi script_text.sh
Press i to switch to the editing mode, enter the following and save the “script_text.sh” script.
#!/bin/bash
echo "Hello Tencent Cloud."
Shell script must start with
#!
and the path to the interpreter reading the script (usually/bin/bash
). For more information on Shell script, see BASH Programming of the Linux Documentation Project (tldp.org) (http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html).
# Base64 encoded script
base64 script_text.sh
You will see the following information:
# Encoded result
IyEvYmluL2Jhc2gKZWNobyAiSGVsbG8gVGVuY2VudCBDbG91ZC4iCg==
# Decode the returned result with Base64 and verify whether it is the command to be executed.
echo "IyEvYmluL2Jhc2gKZWNobyAiSGVsbG8gVGVuY2VudCBDbG91ZC4iCg==" | base64 -d
You can launch an instance through multiple methods, and here we introduce two of them. Choose a method according to your requirements:
script_text
script is IyEvYmluL2Jhc2gKZWNobyAiSGVsbG8gVGVuY2VudCBDbG91ZC4iCg==
.NoteTencent Cloud CVM executes the script using the open-source software cloud-init. For more information about cloud-init, see cloud-init's official website.
Was this page helpful?