[mdlug] Remote shell scripts via ssh?

Ingles, Raymond Raymond.Ingles at compuware.com
Thu Mar 1 08:25:56 EST 2007


> From: David Favro

> Ingles, Raymond wrote:
> >  ssh user at machine.a.org <local_script.sh
> >  doesn't work either.
> Why not?  Are you sure that it doesn't work?  It works for me just as
> you state it, although for efficiency I usually add the '-x' and '-T'
> arguments to ssh.  Perhaps your environment is different from mine.

 To be precise, simple scripts work, more complicated ones do not.

$ cat demo.sh 
#!/bin/sh
#Setting 'UNIX95' is needed to get ps to behave POSIXly on AIX
UNIX95=true
export UNIX95
ps -e -o pcpu= -o comm= | sort -r -n | head -n 10 > top10.tmp
TOP10=`cat top10.tmp`
MAXIE=`echo ${TOP10} | cut -d" " -f 1`
echo "Biggest:"; echo ${MAXIE};
cat top10.tmp
rm top10.tmp

$ ssh user at host "/bin/sh -s " < demo.sh 
Biggest:
25.0
25.0 /usr/local/ccm/merge/bin/mergeahead
 0.3 /opt/OBSDssh/sbin/sshd
 0.2 fsflush
 0.2 /usr/sbin/nis_cachemgr
 0.1 ps
 0.1 csh
 0.1 /opt/OBSDssh/sbin/prngd
 0.0 xterm
 0.0 vi
 0.0 vi

$ ssh user at host < demo.sh 
Pseudo-terminal will not be allocated because stdin is not a terminal.
Warning: no access to tty; thus no job control in this shell...
Sun Microsystems Inc.   SunOS 5.8       Generic February 2000
You have new mail.
UNIX95=true: Command not found
export: Command not found
top10.tmp: File exists
TOP10=`cat top10.tmp`: Ambiguous
TOP10: Undefined variable
MAXIE=: Command not found
Biggest:
MAXIE: Undefined variable
logout

 The scripts I'm working with need to run on as many Unix variants as
possible. And, ideally, it shouldn't be hard to write these scripts;
anything that would run on the remote host via "./script.sh" should
work remotely, too. So far, using "/bin/sh -s" seems to meet these
requirements, whereas just piping the script in raw does not...

 Sincerely,

 Ray Ingles                                       (313) 227-2317

       "We should post this information on the Internet!"
                   - Milhouse Van Houten
 "No! We have to reach people whose opinions actually *matter*!"
                       - Bart Simpson
The contents of this e-mail are intended for the named addressee only. It contains information that may be confidential. Unless you are the named addressee or an authorized designee, you may not copy or use it, or disclose it to anyone else. If you received it in error please notify us immediately and then destroy it. 



More information about the mdlug mailing list