[mdlug] Remote shell scripts via ssh?

Ingles, Raymond Raymond.Ingles at compuware.com
Mon Feb 26 15:11:26 EST 2007


> From: Wojtak, Greg

> Actually, this works:
> 
> echo "command" | ssh user at machinea `'>>'`

For a single command, yes; not for a real script. :-/ Here's what I get:


Single command:
---------------

$ echo "ls /tmp"| ssh -t @remote.linux.box.org `'>>'`
bash: >>: command not found
Pseudo-terminal will not be allocated because stdin is not a terminal.
Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.
stty: standard input: Invalid argument
env.properties.18590
hsperfdata_pfhbzs0/
hsperfdata_root/
install.dir.1100/
install.dir.1446/
install.dir.1732/
install.dir.17439/
install.dir.17705/
install.dir.17994/
install.dir.18590/
install.dir.2084/
install.dir.22069/
install.dir.2349/
install.dir.25263/
install.dir.2659/
install.dir.2955/
install.dir.30272/
install.dir.30455/
install.dir.3611/
install.dir.4116/
install.dir.4302/
keyring-jnQjLV/
keyring-MeIU8L/
lost+found/
mapping-root=
persistent_state

An example script to execute:
-----------------------------

$ cat remtest.sh 
#!/bin/sh
ps -e -o pcpu= -o comm= | sort -r -n | head -n 10 > top10.tmp
TOP10=`cat top10.tmp`
FIRSTPLACE=`echo ${TOP10} | cut -d" " -f 1`
echo "Biggest CPU usage:"; echo ${FIRSTPLACE}; echo "Top 10:"
cat top10.tmp
echo "Finished."
rm top10.tmp

Output of example script run locally:
-------------------------------------

$ ./remtest.sh 
Biggest CPU usage:
4.5
Top 10:
 4.5 firefox-bin
 1.0 public.sh
 0.5 jpilot
 0.0 xpdf.bin
 0.0 watchdog/0
 0.0 usb-storage
 0.0 usb-storage
 0.0 udevd
 0.0 telnet
 0.0 syslogd
Finished.

Trying to run it remotely:
--------------------------

$ cat public.sh| ssh -t ray at remote.linux.box.org `'>>'`
bash: >>: command not found
Pseudo-terminal will not be allocated because stdin is not a terminal.
Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.
stty: standard input: Invalid argument
TOP10=7.0: Command not found.
TOP10: Undefined variable.
FIRSTPLACE=: Command not found.
Biggest CPU usage:
FIRSTPLACE: Undefined variable.

> On 2/26/07 2:28 PM, "Wojtak, Greg" 
> <GregWojtak at quickenloans.com> wrote:
> 
> > what about something stupid like cat local_script.sh | ssh
> > user at machine.a.org (cat '>>' /tmp/script_from_beyond.sh;
> > script_from_beyond.sh)

 Can't seem to get that working either. :-/

 Sincerely,

 Ray Ingles                                      (313) 227-2317

     If the Bush administration can't sort New Orleans out,
               what are their chances in Iraq?
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