It is currently Thu Nov 15, 2018 9:06 am


All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: perl script auto start external dynamips
PostPosted: Wed Oct 21, 2009 7:45 pm 
Offline

Joined: Fri Nov 07, 2008 12:04 pm
Posts: 179
Location: Netherlands
Code:
#!/usr/bin/perl -w

use strict;

my $dynamips = '/home/ios/dynamips-0.2.8-RC2-amd64.bin';
my @ports = ('7200', '7201', '7202', '7203');
my $proc_limit = '70';

foreach my $port(@ports) {
    my $pid = `ps -ef | grep -v grep | grep dynamips | grep $port | tr -s ' ' |  cut -d ' ' -f 2`;
    if (!$pid) {
        exec ("nice -n 19 $dynamips -H $port >> /dev/null 2>&1 &") or print STDERR "Error: $!";
    } else {
        chomp($pid);
        my $pid_cpulimit = `ps -ef | grep -v grep | grep cpulimit | grep $pid | tr -s ' ' |  cut -d ' ' -f 2`;
        if (!$pid_cpulimit) {
            exec ("/usr/bin/cpulimit --pid $pid --limit $proc_limit >> /dev/null 2>&1 &");
        }
    }
}

my @cpulimit = `ps -ef | grep -v grep | grep cpulimit | tr -s ' ' |  cut -d ' ' -f 2`;
if ($#cpulimit > $#ports) {
    chomp($cpulimit[0]);
    `kill $cpulimit[0] >> /dev/null 2>&1 &`;
}


I'm using this script to have some external dynamips started all the time.

If U work as a network admin and have access to a lot of linux powerfull machines, this is perfect.
set cron as follows:

*/1 * * * * /home/ios/gns3_addon.pl

last part of the script will kill old cpulimit daemons, sometimes, when U stop all routers, dynamips daemons will die with a segmentation fault error. but the cpulimit daemon will remain.

I have the number of ports equal to the number of cores. dynamips is not a multicore program, so this is ok.

I hope this will be good for somebody.



_________________
Image Image Image Image ImageImage


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

phpBB SEO