ssh and remote command exec `uname -r`

Hi guys,

I am trying to do a ssh for performing a set of actions.
Find it below:

I need to put the user/ kernel/ DISTRO variables before I complete this operation.
what I observed is when ever I put a `command` in those quotes, it performs thta action in local system rather than remote one.

#!/bin/bash
BUILDDIR=$PWD
ssh sna4 "
echo $pwd;
mkdir testing_dir;
cd testing_dir;
echo $HOSTNAME@$PWD;
pwd;
uname -n;
echo $BUILDDIR;
whoami ;
uname -n;
x=`uname -n`
echo $x
echo "jfhjfhhfjkjfh" > xx;
cat xx
"
If I want to store a data like that how can do using just ssh.

Regards,
Mukund Jampala

#!/usr/bin/bash
date=`date '+%d'`
for i in `cat /export/home/ss0747/scripts/hosterror`; do
ssh $i "uname -a;date;echo;/usr/local/bin/sudo tail -100 /var/adm/messages | egrep 'error|warning' | grep $date; uname -a;echo;echo;echo;echo;echo"
done

This is an example how to execute lots of commands on a ssh server.

  • Make sure to always put an ; at the end of a command
    Cheers
    gnom

Consider using ' quotes around the commands to be executed on the remote host instead of ". This will mean that backquotes will be handled remotely. However it will also mean that variable expansions (e.g. $HOSTNAME) will also be handled remotely.

i would also suggest to use the -n flag to ssh inside a loop

if used with ssh' commands ', the MACROS defined in the script file do not get carry forwarded after ssh. I mean I am not able to use those MACROS in the ssh commands.

By "macros" I presume you mean "variables", which is exactly what I said.

In that case, use " quotes, but escape the backquotes to protect them from being interpreted by the shell on the local system, e.g.

x=\`uname -n \`