#!/bin/sh

# defines constant
default_timeout=5

timeout=$default_timeout
if [ -z $1 ]; then
    echo 'Usage: rsh.sh [-t timeout] command'
    echo ' ex) rsh.sh -t 5 a5555.google.com '
    echo ' ex) rsh.sh a5555.google.com '
    exit;
fi

param=$*
while getopts ":t:" opt; do
    case $opt in
        t ) timeout=$OPTARG;;
        \? ) echo "invalid option"
             exit;;
    esac
done

#$1->$0
shift $(($OPTIND - 1))

# background process
rsh "$@" &
backprocess=$!
sleep $timeout; kill -9 $backprocess; echo "time out $timeout seconds"
exit -1;

 

사용법


#!/usr/bin/perl
# rcmd(host, rcmd, lcmd)
sub rcmd {
  my $RSH = "/home/www/work/rsh.sh -t 1";
  chomp $RSH;
  my $RESULT = "";
  if($#_ == 1) {
     $RESULT = `$RSH $_[0] $_[1]`;
  } else {
    $RESULT = `$RSH $_[0] $_[1] | $_[2]`;
  }
  chomp $RESULT;
    return $RESULT;
}
rcmd("a55384", "ls -al");



 

 

Posted by 김용환 '김용환'

댓글을 달아 주세요