我使用curl通过HTTP get请求从服务器拉取主机名,并且运行良好。我需要我的脚本来修改/etc/sysconfig/network文件,这样我就不必重新启动系统来应用主机名了。
到目前为止,我的代码如下:
#!/usr/local/bin/perl
use strict;
use warnings;
use Sys::Hostname;
my $curl = `curl http://100.10.10.10/hostname`; # Get correct hostname
my $host = hostname;
if ($curl ne $host) {
# Need to modify the /etc/sysconfig/network file to replace hostname or add it.
}编辑:我的实际问题:用新主机名修改该文件的最佳方式是什么?
发布于 2012-09-21 01:25:21
我猜你想要的是
my $host = qx{hostname};而不是
my $host = hostname;另外,为什么不手动更改(例如,打开/etc/hosts或任何您想要编辑的文件,然后编辑,只需确保$>为0...脚本以root用户身份运行)。
https://stackoverflow.com/questions/12516099
复制相似问题