Help Center/ Object Storage Service/ Tools Guide/ obsutil/ Best Practices/ Setting obsutil Commands as Built-in Commands
Updated on 2024-05-17 GMT+08:00

Setting obsutil Commands as Built-in Commands

Scenario

Because obsutil is external software, you need to access the directory where obsutil resides before running obsutil commands, which is not convenient.

An OS provides built-in commands so that the command-dependent directories are loaded to the memory when the system is started. In this way, you can run the commands in any directory, which improves the tool's usability.

This section introduces how to set obsutil commands as built-in commands in different OSs.

Setting obsutil Commands as Built-in Commands in Windows

Option 1: Automatic configuration by running a script (recommended)

  1. Go to the directory where the obsutil tool is located.
  2. Ensure that setup.bat and obsutil.exe are in the same directory. Double-click the setup.bat file.
  3. Check whether the configuration is successful: Run the obsutil help command in the CLI. If the help information is displayed, the configuration is successful.

    If the message 'obsutil' is not recognized as an internal or external command, either an operable program or batch file is displayed after you run the obsutil help command when the automatic configuration completes, the configuration fails. In this case, manual configuration is required.

Option 2: Manual configuration

  1. In the CLI, run the echo %PATH% command to query all the paths configured in the current system. Then select one as the operation path.
  2. Run the mklink PATH/obsutil.exe OBSUTIL_PATH command to set obsutil commands as built-in commands in the system.

    PATH indicates the operation path selected in step 1. OBSUTIL_PATH indicates the absolute path of obsutil.exe.

  3. Check whether the configuration is successful: Run the obsutil help command in the CLI. If the help information is displayed, the configuration is successful.

Setting obsutil Commands as Built-in Commands in Linux or macOS

Option 1: Automatic configuration by running a script (recommended)

  1. Run the script with the path of obsutil as the parameter. Assume that obsutil is stored in the /home/user1 directory. Run the following command:

    source setup.sh /home/user1/obsutil
    • You must execute the script as user root.
    • The script parameter is the relative or absolute path of obsutil.
    • You must run the source setup.sh or . setup.sh command to execute the script.

  2. Check whether the configuration is successful: Run the obsutil help command in any directory. If the help information is displayed, the configuration is successful.

    If the message -bash: obsutil: command not found is displayed after you run the obsutil help command when the automatic configuration completes, log in to the Linux or macOS CLI again. If the problem persists, manual configuration is required.

Option 2: Manual configuration

  1. Run the following command to create a directory for the obsutil tool:

    mkdir /obsutil
    • Skip this step if the directory already exists.
    • You must run the command as user root.

  2. Run the following command to grant the 755 permission for the tool's directory:

    chmod 755 /obsutil
    • Skip this step if the permission for the directory is drwxr-xr-x.
    • You must run the command as user root.

  3. Copy the obsutil tool to the directory created in step 1 and change its permission to 711. Assume that the original path of the tool is /home/test/obsutil. Run the following command:

    cp /home/test/obsutil /obsutil
    chmod 711 /obsutil/obsutil

  4. Run the vi /etc/profile command, type i to enter the Insert mode to edit the file. Add export PATH=$PATH:/obsutil at the end of the file. Then press ESC to exit the editing mode, and then type :wq! and press Enter to save the file and exit.

    Skip this step if the new line already exists in the /etc/profile file.

  5. Run the echo $PATH command to query the current environment variables. If :/obsutil in included in the query result, indicating that the /obsutil environment variable already exists, go to the next step. Otherwise, run the source /etc/profile command.
  6. Check whether the configuration is successful: Run the obsutil help command in any directory. If the help information is displayed, the configuration is successful.

FAQs

  1. How do I locate the obsutil configuration file after setting obsutil commands to built-in commands?

    The .obsutilconfig file in the same directory where obsutil commands reside is the configuration file of the obsutil tool. You can also run the obsutil config command to obtain the configuration file path. An example is provided as follows:

    obsutil config
    Config file url:
      D:\tools\.obsutilconfig
  2. How do I delete obsutil commands after setting them as built-in commands?
    • In Windows:
      1. Run the where obsutil command to locate the path of obsutil commands.
        where obsutil
        E:\tools\bin\obsutil.exe
      2. Run the del PATH command to delete obsutil commands.
        del E:\tools\bin\obsutil.exe

        Replace PATH with the path of obsutil commands. E:\tools\bin\obsutil.exe is used in the preceding example.

    • In Linux or macOS:
      1. Run the which obsutil command to locate the path of obsutil commands.
        which obsutil
        /obsutil/obsutil
      2. Run the rm -rf PATH command to delete obsutil commands.
        rm -rf /obsutil/obsutil

        Replace PATH with the path of obsutil commands. /obsutil/obsutil is used in the preceding example.

      3. Restore the system environment variable: Delete the path of obsutil that is set in the /etc/profile file.

        If the /etc/profile file contains line export PATH=$PATH:/obsutil, delete the line. Or if the file contains line export PATH=$PATH:/test/bin:/obsutil:/test1, delete :/obsutil from the line.

  3. What should I do if the execution of built-in obsutil commands fails in Linux or macOS?
    • If the message Permission denied is displayed after executing obsutil help, run the chmod 755 OBSUTIL_PATH command (replace OBSUTIL_PATH with the path of obsutil) to add an execute permission for the obsutil tool.
    • If the message command not found is displayed, log in again.
    • If the message Cannot create parent folder for xx/.obsutilconfig, xx Permission denied is displayed, check whether the home directory of the user exists.

      In the Ubuntu OS, if you run the useradd command to add a user, the home directory of the user is not created by default. You need to create it manually. Therefore, you are advised to run the adduser command to add a user.

  4. What can I do if no log file is generated after running built-in obsutil commands in Linux or macOS?

    If you have properly configured sdkLogPath and utilLogPath in the configuration file, but still no log file is generated after command execution, then check whether the user who runs the command has the read and write permissions on sdkLogPath and utilLogPath.