use Getopt::Std; shift(@ARGV); &getopts("f:t:s:u:p:"); print "ZAXML-TXT\n"; my $Filepfad; my $Volumetype; my $Username; my $Password; my $Searchpattern; print "${opt_f}"; if ($opt_f) { $Filepfad=$opt_f; } else { print "CURRVALUE_STRING: a File-Path must be given\n"; print "RETURNID: 1\n"; exit 0; } if ($opt_t){ if ($opt_t ne "UNC" && $opt_t ne "local" && $opt_t ne "NFS" && $opt_t ne "SMB") { print "CURRVALUE_STRING: Filesystem-type must be UNC, local, NFS or SMB\n"; print "RETURNID: 1\n"; exit 0; } elsif ($opt_t eq "SMB") { $Volumetype=$opt_t; if ($opt_u && $opt_p) { $Username=$opt_u; $Password=$opt_s; } else { print "CURRVALUE_STRING: Username and Password are required for access to SMB-Shares\n"; print "RETURNID: 1\n"; exit 0; } } else { $Volumetype=$opt_t; } } else { print "CURRVALUE_STRING: Volumetype must be given\n"; print "RETURNID: 1\n"; exit 0; } if ($opt_u){ $Username=$opt_u; } if ($opt_p){ $Password=$opt_p; } if($opt_s) { $Searchpattern = $opt_s; } else { print "CURRVALUE_STRING: a Searchpattern must be given\n"; print "RETURNID: 1\n"; exit 0; } my $os=$^O; my $last_slash; if ($os eq "MSWin32" && $Volumetype eq "local") { $last_slash = rindex($Filepfad, "\\",); } else { $last_slash = rindex($Filepfad, "/",); } my $Test_Volume=substr($Filepfad,0, $last_slash); if (!(-d $Test_Volume)) { print "CURRVALUE_STRING: Volume does not exist, isn't mounted or can't be read\n"; print "RETURNID: 2\n"; exit 0; } if (-f $Filepfad) { if ( ! unlink($Filepfad) ) { print "CURRVALUE_STRING: can't delete existing File ${Filepfad}\n"; print "RETURNID: 2\n"; exit 0; } } my $Filehandle; if(!(open($Filehandle, '>', $Filepfad))) { print "CURRVALUE_STRING: can't create new file ${Filepfad} for write access \n"; print "RETURNID: 2\n"; exit 0; } if(!(print $Filehandle "Test")) { print "CURRVALUE_STRING: Couldn't write into File\n"; print "RETURNID: 2\n"; exit 0; } if(!(close $Filehandle)) { print "CURRVALUE_STRING: can't close file ${Filepfad} after writing\n"; print "RETURNID: 2\n"; exit 0; } if(!(open($Filehandle, '<', $Filepfad))) { print "CURRVALUE_STRING: can't create new file ${Filepfad} for read access \n"; print "RETURNID: 2\n"; exit 0; } while ($Content = <$Filehandle>) { chomp $Content; if ($Content eq $Searchpattern) { print "CURRVALUE_STRING: Files can be written and read\n"; print "RETURNID: 3\n"; exit 0; } else { print "CURRVALUE_STRING: File can be written but not read or file-content does not match Searchpattern\n"; print "RETURNID: 4\n"; exit 0; } #else }#while