You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何gcloud DNS记录更新命令在终端直接执行正常,在Bash脚本中运行却报错?

Fixing gcloud DNS Record Update Failure in Your Bash Script

Looks like the issue comes from hidden extra characters in your script that are messing up the --zone parameter. Let's break this down:

What's Going Wrong?

Your error message shows the managed zone is being interpreted as pixelcraft (notice the trailing space at the end), but your actual zone name is pixelcraft without the space. This usually happens when:

  1. Your script was edited on a Windows machine, which uses CRLF (\r\n) line endings instead of Linux's LF (\n). The hidden \r character gets appended to the end of your --zone=pixelcraft parameter, making gcloud look for a zone named pixelcraft\r (which shows up as pixelcraft in error messages).
  2. There's an accidental trailing space after pixelcraft in your script's --zone argument (though looking at your script code, this seems less likely).

How to Fix It

Here are a few straightforward solutions:

  • Convert line endings to Linux format:
    Run this command on your script to convert CRLF to LF:

    dos2unix your_script_name.sh
    

    If dos2unix isn't installed, you can install it first with:

    sudo apt install dos2unix
    
  • Manually retype the gcloud commands in your script:
    Sometimes copy-pasting code from Windows editors or other sources brings in hidden characters. Open your script in a Linux text editor (like nano or vim) and retype the three gcloud dns record-sets update lines from scratch, making sure there are no trailing spaces after pixelcraft.

  • Add quotes around variables (good practice anyway):
    While not the root cause here, wrapping your $IP_ADDR variable in double quotes prevents issues if the IP ever has unexpected whitespace (unlikely here, but a safe habit):

    gcloud dns record-sets update other.pixelcraftserver.net --rrdatas="$IP_ADDR" --type=A --zone=pixelcraft
    

Verify the Fix

After making these changes, run your script again. If you want to test first, execute the full command directly in your terminal to confirm it works (which you said it does), then ensure the script version matches exactly.

内容的提问来源于stack exchange,提问作者Pixonepro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 14:13:10