#!usr/bin/perl
	$home=$ENV{'HOME'};
	$home="$home"."/NDATE/FILER_INFO/";
	opendir(DIR,"$home") ||die("Unable to open the directory $!");
	@files=readdir(DIR);

	foreach $file(@files){
		$file_open="$home"."$file";
		open(FIN,"<$file_open")||die("Cant open $!");
		@data=<FIN>;
		if($data[0]=~/hostname=/){	
			system("sudo chmod 766 $file_open");
			system("rm $file_open");
			open(FOUT,">$file_open");

			for($line=0;$line<scalar@data;$line++){
				if($data[$line] =~ /^MGMT_IP\=(\d+\.\d+\.\d+\.\d+)/){
					$ip=$1;
				}
				if($data[$line]=~/default_password=(\S+)/){
					$password=$1;
				}

				if(($data[$line] =~ /^conn c-login\s\{conntype/)&&($data[$line+1] !~ /^conn c-system\s+\{prompt_password=netapp1!\}/)){
					if(($data[$line+3] !~ /^conn c-system\s+\{prompt_password=netapp1!\}/)&&($data[$line+2] !~ /^conn c-system\s+\{prompt_password=netapp1!\}/)){
						print FOUT "$data[$line]conn c-system {prompt_password=netapp1!}\n";
						next;
					}
		}
				if(($data[$line] =~ /^conn c-system\s+\{prompt_password=netapp1!\}/) && ($data[$line+1] !~ /^conn c-system/)&&($data[$line-1] !~ /^conn c-system/)){
					print FOUT "$data[$line]conn c-system {conntype=ssh-persist;connhost=$ip;username=admin;password=$password}\nconn c-system {initial_command=\"set -privilege test;systemshell -node local\"}\n";
				}
				else{
					print FOUT "$data[$line]";
				}
			}
		system("chmod 755 $file_open");
		}
}
