ssh and remote command exec `uname -r`


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh and remote command exec `uname -r`
# 1  
Old 05-06-2008
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
# 2  
Old 05-06-2008
#!/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
# 3  
Old 05-06-2008
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.
# 4  
Old 05-07-2008
i would also suggest to use the -n flag to ssh inside a loop
# 5  
Old 05-07-2008
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.
# 6  
Old 05-07-2008
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.

Code:
x=\`uname -n \`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

Ssh remote command and print same line

john-test:/root> ssh -q chicago-ser uname;date Linux Fri Oct 13 16:41:11 GMT 2017 How I can print on the same line like this : Linux Fri Oct 13 16:41:11 GMT 2017 (2 Replies)
Discussion started by: jhonnyrip
2 Replies

3. Shell Programming and Scripting

Execute command on remote host via ssh

How should i make the following code working #!/bin/bash INPUTFILE="test.txt" while read STRING; do IP=`host -t A $STRING | awk '{print $NF}'` HOSTNAME=`ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no $IP "hostname"` echo $HOSTNAME > out.txt done < $INPUTFILE At this moment while... (3 Replies)
Discussion started by: urello
3 Replies

4. Shell Programming and Scripting

Remote command in variable using ssh

Hi, I've an issue in a shell script: I'm opening an ssh connection to a remote server, then I want to store the result of a ls command in a variable, but it doesn't work: the ls is done on the local machine. ssh user@server << EOF ls # works as expected (ls is done remotely) test=`ls` # the... (1 Reply)
Discussion started by: seloum57
1 Replies

5. Shell Programming and Scripting

ssh - running remote command not exiting

Hi, i have a shellscript, where in i need to connect to different server start these three jobs and exit from the server and start the same three jobs on local server. ssh user@remotehost 'bash -s' << EOF ${GETT_HOME}/bin/start1 & sleep 10 ${GETT_HOME}/bin/start2 & sleep 10... (1 Reply)
Discussion started by: swapnabhargav
1 Replies

6. Shell Programming and Scripting

ssh to remote command prompt

Hi all, Scenario - trying to run a batch job on a second machine. DIR=directory user=user server=server Here is what i have- ssh user@server 'sleep2; cd $DIR; <jobname>' I have got access to the correct directory, i checked with a pwd command previous. Problem is the job i... (1 Reply)
Discussion started by: Hopper_no1
1 Replies

7. Shell Programming and Scripting

SSH execute remote command (with jump)

Hi all, I am facing the following issue: Host A should execute a remote command (say pwd) on host B2. B2 is not directly reacheable but you have to connect from a to B1, then from B1 you can execute the command ssh user@B2 pwd. B1 and B2 are directly connected: A => B1 => B2 | ... (3 Replies)
Discussion started by: Evan
3 Replies

8. Shell Programming and Scripting

passing arguments in remote ssh command?

i have a bash script on serverA, when i run the script on the server, it runs fine. the way to run the script is like this ./script "option1" Now i am trying to call it from local laptop using ssh command, my command is as the following ssh serverA ~/script "option1" and i got error... (7 Replies)
Discussion started by: fedora
7 Replies

9. UNIX for Dummies Questions & Answers

doubt in ssh command for remote login

Hello sir, Im using ubuntu distro. We all know that ssh is used for password less entry.So, I have the public key and the IP address and the username thats it. Now to login it to the system either I should have password or a private key.Now I have the blacklist of private/public keys. But I dont... (1 Reply)
Discussion started by: nsharath
1 Replies

10. Shell Programming and Scripting

ssh remote command not sourcing bashrc

Hi, WHen I login to the host using ssh, it sources bash_profile then bashrc file, and reads in my path and other variables. But when I want to execute a command remotely, it is not sourcing my bash_profile or bashrc files and I dont get the env I want. THis is causing a lot of problems. HOw... (1 Reply)
Discussion started by: sardare
1 Replies
Login or Register to Ask a Question