in reply to Passing the shell script in ssh->cmd option
No problem! I do this all of the time with Net::SSH::Perl. You must make sure you have your quotes and escapes correct (which usually takes a bit of fiddling), but I usually build the scripts up command-by-command while testing them out. Also remember that you usually get /bin/sh as your shell unless you specify otherwise.
I usually end up with things as shown below. This particular ksh shell script will log the event in a logfile, then pre-process what I send on STDIN via Net::SSH::Perl, and provide it to a local command on the destination machine. The results ends up in $stdout.
my $cmd = '/usr/bin/ksh -c \' LOGDIR=/log/predecode LOGFILE=$LOGDIR/usage`date \'+%m\'` if [ -w $LOGFILE ] ; then echo "$LOGNAME; `date \"+%D %T\"`;`uname -a`;${DISPLAY:-SS +H:$SSH_CONNECTION}" >>$LOGFILE fi while read LINE do if [ "$LINE" == "" ] then continue; fi PRE="${LINE%%\|*}" POST="${LINE#[0-9]*\|}" if [ "${POST%%[A-Z]*}" == "_" ] then print "$PRE|$POST" continue; fi ( print -n "$PRE|"; echo $POST | ' . /usr/bin/farendcommand . ' print "\n" ) done\''; my ($stdout, $stderr, $exit) = $ssh->cmd($cmd, $inputForFarEnd);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing the shell script in ssh->cmd option
by saravanansh (Initiate) on Jan 07, 2009 at 11:19 UTC |