#! /usr/bin/perl

use warnings;
use strict;

my $mmcs_cmd = "/bgsys/drivers/ppcfloor/bin/mmcs_db_console";
#my $mmcs_cmd = "/bin/cat";

sub main
{
	my ($pname) = @ARGV;

	if (!defined($pname)) {
		print "NOT_OK\n";
		exit 1;
	}
	
	do_mmcs("free $pname", "quit");

	print "OK\n";

	return 0;
}

sub do_mmcs
{
	my @cmds = @_;
	my $cmd;
	my @result;

	unlink("/tmp/fout.$$");

	open(FOUT, "> /tmp/fout.$$") or die "Bad open";
	foreach $cmd (@cmds) {
		print FOUT "$cmd\n";
	}
	close(FOUT);

	$ENV{"DB_PROPERTY"} = "/bgsys/local/etc/db.properties";
	$ENV{"LD_LIBRARY_PATH"} = "/dbhome/bgpsysdb/sqllib/lib64:/dbhome/bgpsysdb/sqllib/lib32";

	@result = `. /etc/profile.d/bgp.sh ; $mmcs_cmd < /tmp/fout.$$ 2>&1`;

	unlink("/tmp/fout.$$");

	return @result;
}

exit main();

