Running test command in ssh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running test command in ssh
# 1  
Old 10-16-2015
Running test command in ssh

I tried to run the following commands in my shell script.

This command works fine for me:
Code:
ssh -n "${username}"@"${hostname}" "grep WARNING ${serverhome}/${serverlog} | wc -l"

The result is:
1548

However when i try to run a similar one:
Code:
ssh -n "${username}"@"${hostname}" "test `grep -q WARNING ${serverhome}/${serverlog}` && echo warning || echo good"

I get:
Code:
grep: /home/test-user/server/server.*.log: No such file or directory

I suspect i did not use the proper quote characters in the second command. But i don't know how to fix it. Thanks for the help.

Last edited by zaxxon; 10-16-2015 at 03:55 AM..
# 2  
Old 10-16-2015
Hi try something like:
Code:
ssh -n "${username}@${hostname}" grep -q WARNING "${serverhome}/${serverlog}" && echo warning || echo good

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 10-22-2015
Problem revisited:
-----
The above approach would not be right since it would give the wrong result if the ssh command failed. So a better approach may be to let the other side provide the echo:
Code:
ssh -n "${username}@${hostname}" "grep -q WARNING \"${serverhome}/${serverlog}\" && echo warning || echo good"

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sudo ssh with command running in background

I am trying to run a command. This is one of my attempts: for i in fileservera; do ssh -t $i 'sudo ls /';doneThis works, and I see the directories. However, what I want to do now is start a process on the remote server such as /usr/bin/connectproc -standalonesudo /usr/bin/connectproc... (1 Reply)
Discussion started by: newbie2010
1 Replies

2. Shell Programming and Scripting

Running command using SSH

Hi All, I am trying to run my script using ssh. Below is the code snippet #!/bin/bash ssh username@useipapd03 'bash -s' #To ensure If JMSdirectory exists or not if then echo "JMS mounts................exist'>>OutputResult.txt else echo "JMS mounts................not... (10 Replies)
Discussion started by: sharsour
10 Replies

3. 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

4. Linux

YUM HANGS AT RUNNING TRANSACTION TEST

Hi When i trying to update using yum, hangs at Running transaction test. # yum update yum Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * addons: ftp.oss.eznetsols.org * extras: ftp.oss.eznetsols.org * base: ftp.oss.eznetsols.org * updates:... (2 Replies)
Discussion started by: anil8103
2 Replies

5. Infrastructure Monitoring

Test if Oracle listener is running

Hi All , I am new to shall scripting, i want write an script for oracle tns and listener. If tns working i want o/p as "Listener and TNS are working" else o/p should be ""Listener and TNS are not Working" below is the command in unix to check the tns status, if no output it means TNS... (3 Replies)
Discussion started by: abdul bari
3 Replies

6. Shell Programming and Scripting

Cron job giving error while running SSH command

Hi All, The script which i am using to SSH to remote server is working fine when i run is using ./ but when cron runs it it gives error that "ssh: not found" please help!!! (3 Replies)
Discussion started by: visingha
3 Replies

7. Shell Programming and Scripting

Script to test for scripts running

Hi, Im writing a script that will check which scripts are running. The script will run on a 5min loop and the status of the scripts will be written to the log. If any of the scripts arent running an email will be sent out. At the min if all scripts are running an entry is made to the log... (19 Replies)
Discussion started by: runnerpaul
19 Replies

8. Linux

running test

-------------------------------------------------------------------------------- I am running a test command and if the user is not found you have to type exit and it wiil exit. Ok I did that. But if the user is found it is supposed to finger them. But my problem is it makes you type exit first... (2 Replies)
Discussion started by: skooly5
2 Replies

9. Shell Programming and Scripting

is running this command via ssh possible? (formatting issues)

Here is the command I want to run: for pkg in `pkginfo | grep -i VRTS | awk '{print $2}'`; do showrev -p | grep $pkg; done | awk '{print $2 "\t" $7}' | uniq It returns the package info in a form such as: 113210-03 VRTSfspro 112392-06 VRTSvmman 113596-03 VRTSvmpro... (1 Reply)
Discussion started by: LordJezo
1 Replies

10. UNIX for Dummies Questions & Answers

Script to Test Application Server is running

Hi, I'm a complete novice at Unix and need to create a script that does the following... checks to see if an application server is running. If the app is running then print 'Available' Else print 'Unavaliable' exit from scriopt I have no idea where to start. I'd be very grateful... (0 Replies)
Discussion started by: duglover
0 Replies
Login or Register to Ask a Question