Reputation: 1523
I using curl
to pull a hostname from a server using a HTTP get request, and that is working fine. I need my script to modify the /etc/sysconfig/network
file so I don't have to restart the system to apply the hostname.
Here is my code thus far:
#!/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.
}
EDIT: My Actual Question: What is the best way for me to modify that file with the new hostname?
Upvotes: 0
Views: 756
Reputation: 8895
I guess you want is
my $host = qx{hostname};
instead of
my $host = hostname;
also, why dont you just make the changes manually (i.e, open /etc/hosts or whatever file you want to edit, and edit, just make sure the $>
is 0... script is running as user root).
Upvotes: 1