My situation is this:
I have cable internet service provided through rcn. Recently they started frowning upon my staticly set ip number, and kept disconnecting my service for doing so. Hence, I decided to do as they wished and use a dynamic ip. The problem then arose that my apache vhost configuration file, and several cgi configuration files needed to be updated every time my ip changed so that they would work. Thus I wrote this script to update my /etc/httpd/conf/virtualhosts.conf file. I also made this script write the file /usr/share/global.ip so that if I had any other scripts that needed my ip i could just put in require "/usr/share/global.ip"; and the put $ipnum everywhere I needed my ip. This all worked.

The problem is this: Some of the configuration files aren't executable so I can't use the global.ip file with them, and also I can't/don't want to imbed long files into the script as I did with the vhost configuration file. Does anyone have any suggestions/comments on how I could improve my system, and more importantly get these text configuration files updated. The following is the code for my script:
#!/usr/bin/perl -w use strict; # a good idea; it brings into existence three strictures my $rawbuf; my $ipbuf; $rawbuf=`/sbin/ifconfig eth0`; if( $rawbuf =~ /(\d+\.\d+\.\d+\.\d+)/ ) { $ipbuf= $1; } else { print "You have no ip address you dazzle-duck! \n"; } vhost($ipbuf); globalip($ipbuf); #-----------------------Behold the function arena--------------------- +# #This function is the template for the apache vhost configuration file +; listen to it sing sub vhost{ my $vfile = "/etc/httpd/conf/virtualhosts.conf"; open (VHOST, "> $vfile") or die "The virtual hosts configuration file +is virtual all right! $!\n"; my $ipnum = "$_[0]"; my @bigbuf = ( "NameVirtualHost $ipnum\n\n", "<VirtualHost $ipnum>\n", "User hg\n","Group hg\n", "DocumentRoot /www/hg\n", "ServerName 0tis.org\n", "ServerAlias www.0tis.org\n", "ScriptAlias /cgi-bin /www/hg/cgi-bin\n", "</VirtualHost>\n" ); while (@bigbuf){ my $printbuf = shift ( @bigbuf ); print VHOST $printbuf; } } #code for global ip template sub globalip{ my $ipnum = "$_[0]"; my $globalip = "/usr/share/global.ip"; open (GIP,"> $globalip") or die "You silly silly man, why must you ins +ist on opening a non-existant configuration file $!\n"; print GIP "\$ipnum = $ipnum;\n1;"; close (GIP); }
~heise2k~

In reply to Updating config files with dynamic ip by gornox_zx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.