我正在尝试将图像启动时的主机名更改为/ 24 - / 32 IPv4地址。我想出了以下脚本,但HNAME仍为NULL:
#!/bin/sh
echo "Changing hostname to IP-related"
HNAME=ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d. -f4 | awk '{ print $1 }'
echo "Proposed hostname is: $HNAME"
echo
hostname=$HNAME
echo "The new hostname is $HOST_NAME"
echo
答案 0 :(得分:0)
我找到了解决方案。感谢@anubhava - 我还修复了原始示例中的一些不一致问题:
#!/bin/sh
echo "Changing hostname to IP-related"
HNAME=ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d. -f4 | awk '{ print $1 }'
echo "Proposed hostname is: $HNAME"
echo
hostname $HNAME
echo "The new hostname is $HNAME"
echo