#/usr/bin/perl use strict; use warnings; use Commands 1.0; sub Get_Client(); my @clients; die "Error. Usage \'perl Command_parser.pl -Noclient | [-Command Client1 Arguments -Command Client2 Arguments...] \'\n $!" unless $#ARGV >= 0; #################################################################### #################################################################### ## If a client was not provided at the command line, get one if (lc($ARGV[0]) eq "-noclient") { Get_Client(); } else { my @current_command; for(my $i = 0; $i <=$#ARGV; $i++) { if ( $ARGV[$i] =~ m/^\-/ && $i != 0) { # eval current command , then wipe it and keep processing my $command_value = eval_cmd(\@current_command); print "Command is :$command_value\n"; ##system($command_value); @current_command = (); push @current_command , $ARGV[$i]; $current_command[0] =~ s/\-//g; } elsif ( $i == $#ARGV ) { # eval last command push @current_command , $ARGV[$i]; my $command_value = eval_cmd(\@current_command); print "Command is :$command_value\n"; ##system($command_value); } else { push @current_command , $ARGV[$i]; if ($i == 0) { $current_command[0] =~ s/\-//g; } } } } #################################################################### #################################################################### ## No client was provided at the command line, fill one in sub Get_Client() { my @current_command = ('backup','mars','file1.txt'); my $cmd_value = eval_cmd(\@current_command); # here magic happens! ##security_check($cmd); ##system("$cmd"); }