To execute a number of commands on a remote machine you can create a file that contains the commands that you want to execute. This file can then be ‘cat’ed to your ssh command. I wrote one command file to test the functionality and called it ‘remoteCommands’. As you can see it is even possible to use constructs like if clauses.
if [ -e /sbin/vxdisk ]
then
vxdisk list | grep -v disk_0 | awk '{ print $1" "$4" "$3 }'
fi
The script is getting a list of known LUNs from servers on the network. The output will look like the one below:
[root@testclient ~]# cat bin/remoteCommands | ssh testdb1
Pseudo-terminal will not be allocated because stdin is not a terminal.
DEVICE GROUP DISK
emc_clariion0_101 ztkuatjrn_dg ztkuatjrn_dsk
emc_clariion0_102 ensuatjrn_dg ensuatjrn_dsk
emc_clariion0_201 ztkuatdb_dg ztkuatdb_dsk
emc_clariion0_202 ensuated_dg ensuated_dsk
emc_clariion0_403 ztkuatewd_dg ztkuatewd_dsk
emc_clariion0_501 ztkbase_dg ztkbase_dsk-a
emc_clariion0_541 ensbaseed_dg ensbaseed_dsk
The warning about the ‘Pseudo-terminal’ can be suppressed by using the ssh option -T.