[英]Shell script not working to append the text at end the hosts/file
尝试 append 在主机文件末尾的文本,但无法通过用户数据工作。
一旦服务器启动,Service_start.sh 脚本将执行某些命令以及 shell 脚本 (hostnames.sh)。 每个脚本都在工作,但不是这个 hostnames.sh,在 output 日志中它显示为成功。 我在 /etc/hosts 中看不到 IP 和主机名
如果我手动运行它,那么它正在工作
Service_start.sh 文件包含
#!/bin/bash
#script to udate hostnames in hosts file
ip=`facter testip`
hostname=`facter testhostname`
sudo /bin/bash /opt/resources/hostnames.sh >> /opt/test.log
和 hostnames.sh 文件包含
#!/bin/bash
#script to udate hostnames in hosts file
ip=`facter testip`
hostname=`facter testhostname`
echo " " >> /etc/hosts
if [ $? -eq 0 ]; then
echo SUCCESS
else
echo FAIL
fi
echo "$ip $hostname" >> /etc/hosts
if [ $? -eq 0 ]; then
echo SUCCESS
else
echo FAIL
fi
您只需要将`更改为"
ip="facter testip"
hostname="facter testhostname"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.