my $ssh = "/usr/local/bin/ssh"; my @ssh_cmd_to_run=($ssh, "-i", $key_file, "user\@$host", "scriptname", "options"); open3(*SSH_IN, *SSH_OUT, *ERROR, @ssh_cmd_to_run); print SSH_IN $parameters_you_dont_want_seen; close(SSH_IN); my $return = ; close(SSH_OUT); my @error=; close(ERROR); #### #!/usr/bin/perl -wT # BEGIN { delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; $ENV{PATH} = ""; } use strict; process_ssh_command($ENV{SSH_ORIGINAL_COMMAND}); exit; sub process_ssh_command { my $ssh_command = shift || ''; if ( ! $ssh_command ){ print "Error: You must specify the command to run\n"; return; } if ( $ssh_command =~ /^scriptname\s+(options_regex)$/ ){ my $options= $1 || ''; # do something if options not set chomp(my $stdin = ); # if you need it # untaint stdin system("/path/to/scriptname", $options); return; } print "Error: Unknown command or incorrect format \"$ssh_command\"\n"; return; }