ssh - to execute set of commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh - to execute set of commands
# 1  
Old 04-28-2010
ssh - to execute set of commands

Hi


Can someone help me to figure out


Want to execute few cmds in remote host thru ssh


Tried below cmd

-------------------------------excerpt-------------------
Code:
 RDIR=/data1/logs  ---> variable stores rem. server directory
 TODAY="`date '+%b %d'`"  
 ssh -i $userid@$host "cd $RDIR;grep -il "ERROR" `ls -l $RDIR|grep $TODAY" |awk  '{print $NF}'` 2>/dev/null|wc -l"

-------------------------------excerpt-------------------

throws below err
Code:
ksh: 27:  not found 
 grep: RE error 41: No remembered search string.

any help would be greatly appreciated

tks

Last edited by Scott; 04-28-2010 at 05:13 AM.. Reason: Please use code tags
# 2  
Old 04-28-2010
Hi.

I wasn't able to test this, but your command should look more like:

Code:
ssh $userid@$host "cd $RDIR;grep -il 'ERROR' \$(ls -l $RDIR | grep \"$TODAY\" | awk '{print \$NF}') | wc -l"


Last edited by Scott; 04-28-2010 at 05:28 AM..
# 3  
Old 04-28-2010
It works......Thanks a lot Scottn
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh multiple hops to execute commands with arguments

Hi I need to write a script to ssh through several hops (e.g. HostA-HostB-HostC-HostD), where Host A does not have direct assess to HostC ; HostB cannot access HostD directly. when I ssh 3 hops and run command with arg1, arg2 and redirect the output to a file, e.g. HostA> ssh -t HostB ssh -t... (3 Replies)
Discussion started by: chiensh
3 Replies

2. Shell Programming and Scripting

Shell script help to execute ssh remote commands

Hi, The below command is not giving me the count , Can somebody help me in re-writing this pls . Proc_Exist=`ssh -q -o "BatchMode=yes" -o "PasswordAuthentication=no" $OAUSER@${Primary_Node} ps -ef | grep -v grep | grep "${ICM_Proc}" |wc -l ` Also the same problem with below... (13 Replies)
Discussion started by: Y.balakrishna
13 Replies

3. Shell Programming and Scripting

how do i execute a set of commands in telnet??

I have list of commands in a file in one sever and i need to execute these set of commands in the server to which i m telnetting to .. (4 Replies)
Discussion started by: nikhil jain
4 Replies

4. UNIX for Advanced & Expert Users

suid with execute set for passwd

Hello All, We could see that suid with execute is set for passwd: -rwsr-xr-x 1 root root 22960 Jul 17 2006 /usr/bin/passwd that means if any user execute command passwd that will be executed with root priviledge then why a normal user was not able to change other user password any... (2 Replies)
Discussion started by: NIMISH AGARWAL
2 Replies

5. Shell Programming and Scripting

connect to multiple servers using SSH and execute commands

Requirement: Run a shell script with below inputs file name checksum path the script should go to multiple servers (around 35) and verify the input cksum and if there is a mismatch display a simple message to the user that cksum verification failed. host details, user id /... (1 Reply)
Discussion started by: amicableperson
1 Replies

6. Shell Programming and Scripting

set Net:SSH:Expect timeout and set it again.

SSHing into a machine can take a few seconds, but after I'm in, the commands return quickly. I was wondering if the timeout setting can be changed once I'm logged into the machine. Does anyone know if this can be set on the fly? The problem here is, if I have to set timeout = 10, it'll take 10... (1 Reply)
Discussion started by: mrwatkin
1 Replies

7. Shell Programming and Scripting

Execute ssh commands through bash script

Hi all! I am trying to write a script that will check if a certain directory is available at several different nodes and then do stuff in it ..... On the beginning of the script I give as a variable the directory and the number of the nodes and then I loop like this: for... (3 Replies)
Discussion started by: idet2
3 Replies

8. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

9. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

10. Shell Programming and Scripting

How to run a set of commands through ssh

I need to run a set of commands on a remote machine using ssh. it should also collect output and return status of each command. Can someone help me how to do this? (1 Reply)
Discussion started by: vickylife
1 Replies
Login or Register to Ask a Question