#!/bin/sh scp script.pl user@remote: result=$(ssh user@remote script.pl) ssh user@remote rm script.pl echo $result