LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-02-2015, 04:52 PM   #16
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880

I know. Old habits...
 
Old 12-04-2015, 09:52 AM   #17
pearemb
LQ Newbie
 
Registered: Dec 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
Yep - this is the error I'm getting

Quote:
")syntax error: invalid arithmetic operator (error token is "
When I use
Quote:
(( result > 0 ))
 
Old 12-04-2015, 10:57 AM   #18
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by pearemb View Post
Yep - this is the error I'm getting
Show the entire code.
And, for the sake of my old eyes, use [code] tags, not [quote] tags.
 
Old 12-04-2015, 02:41 PM   #19
pearemb
LQ Newbie
 
Registered: Dec 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
Code:
result=$(ssh -n -t -t username@$remoteTarget "ps -ef | grep -v grep | grep httpd | wc -l")
echo $result
if (( result > 0 )); then
logMessage "httd running"
ssh -n -t -t username@$remoteTarget "sudo service httpd reload"
else
logMessage "httd not running..starting the service"
ssh -n -t -t username@$remoteTarget "sudo service httpd start"
fi
 
Old 12-04-2015, 03:47 PM   #20
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Quote:
result=$(ssh -n -t -t username@$remoteTarget "ps -ef | grep -v grep | grep httpd | wc -l")
Have you tried running your script without the -n and -t options?
 
Old 12-04-2015, 07:48 PM   #21
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I have the same syntax error when runnng your code. It turns out that result is not a simple number, but contains a carriage return and line feed. To confirm this, pipe result into od -cx.
Perhaps this is related to the -n and -t options. Didn't check.

Thus, you need to tweak the ssh command on the first line.

Rather than counting the lines, leave out the wc command and just check $? after the first ssh. If $? is 0, httpd is running. If non-zero, it's not running.

EDIT: It is related to -n -t, though I can't say exactly how.

EDIT2: Rather than checking $?, you can just write
Code:
if ssh username@$remotetarget $(ps|grep|grep))
then
    echo "http is running"
else
    echo "it's not running"
fi
You can also replace the ps pipe with a service httpd status >/dev/null or systemctl status httpd >/dev/null or whatever makes sense on the remote system.

Last edited by berndbausch; 12-04-2015 at 08:01 PM.
 
Old 12-05-2015, 01:41 PM   #22
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,768

Rep: Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192Reputation: 1192
Consider
Code:
ps -eo comm | grep -c httpd
or
Code:
pgrep httpd | wc -l
Both don't list the args; no need for grep -v grep.
If you must use ps -ef then
Code:
ps -ef | grep -c "[h]ttpd"
The [ ] trick will not find httpd in the grep args.
--
Code:
result=$(ssh -qnx username@$remoteTarget "ps -eo comm | grep -c httpd")

Last edited by MadeInGermany; 12-05-2015 at 01:54 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error while running command in ssh quiet mode karthik4455 Linux - Newbie 7 09-25-2015 05:25 PM
Running adduser command via ssh in a loop massy Programming 4 03-09-2014 10:46 AM
running shell command locally and over ssh PoleStar Linux - Newbie 2 07-22-2012 12:22 PM
Keep running a command when disconnect from SSH stuartornum Linux - General 3 02-17-2006 10:19 PM
problem in running ssh command skvasistha Linux - General 1 11-29-2004 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration