LinuxQuestions.org
Help answer threads with 0 replies.
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 03-25-2011, 05:38 AM   #31
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002

To add to what Eric said, you can also do the following:
Code:
variable1=$(ps aux | grep blah)
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-25-2011, 05:57 AM   #32
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
ok thx, indeed what you said makes more sense !!
and it's working ;-)
Code:
ssh user@host 'myvar=`grep 'ERROR' /home/vusbe/test.txt`; echo $myvar'
ssh user@host 'echo dit is een test'
so it's propably the same for an IF command
i've got this:
Code:
ssh vusbe@wlsdev.intern.vgt.vito.be 'myvar=`grep 'ERROR' /home/vusbe/test.txt`; echo $myvar; if [$myvar == 'ERROR'] then echo 'je hebt een error' fi'
but when i run it i get an error:
Code:
ksh: syntax error at line 1 : `if' unmatched
what does he mean with unmatched?

greetz

Last edited by brownie_cookie; 03-25-2011 at 05:58 AM.
 
Old 03-25-2011, 06:15 AM   #33
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

You need a space between [ and $myvar and ERROR' and ]. Also look at the links I pointed to and check the reference card I pointed you to. Your quotation is off. You really need to read at least the basic guide to Bash I pointed you to.

Kind regards,

Eric
 
Old 03-25-2011, 06:21 AM   #34
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
i've read the section about the IF
if

and this is my code (i followed the site):
Code:
ssh user@host 'myvar=`grep 'ERROR' /home/vusbe/test.txt`; echo $myvar; if [ $myvar=ERROR ] then echo "je hebt een error" fi'
and i still get the if unmatched error

but i will look further on the site (and i'm reading it, but only the parts i think i need, because it's a big site a lot to read)

EDIT:
it's working...

Code:
ssh user@host 'myvar=`grep 'ERROR' /home/vusbe/test.txt`; echo $myvar; if [ $myvar=ERROR ]; then echo "je hebt een error"; fi'

Last edited by brownie_cookie; 03-25-2011 at 06:24 AM.
 
Old 03-25-2011, 06:26 AM   #35
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

See you can do it! Congrats. You realized what was wrong? Ok, on to the next step. You'll get there.

Kind regards,

Eric
 
Old 03-25-2011, 06:30 AM   #36
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
yes, i forgot my semicolons... stupid

so after each part of an expression (like if) it needs a ';' ?

now i'm going to experiment with IF, so normally i shall not have any further question for a couple of hours
but when i do, i'll post them here ;-)

Eric, thank you for helping me out and thank you for having patience with me !!

Greetings

P.S.: a quick question, can i use != ? like
Code:
$myvar!=ERROR

Last edited by brownie_cookie; 03-25-2011 at 06:32 AM.
 
Old 03-25-2011, 06:36 AM   #37
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

Indeed, commands should be ended by ;. Whenever you're in doubt, look at the Bash Guide and if you cannot find the answer post here. You're welcome, no problem at all.

About your question: Have a look here. What do you think? Also remember quotations and difference between = and ==.

Kind regards,

Eric
 
Old 03-25-2011, 07:40 AM   #38
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
Ok, i've got a strange thing..
i think this is a right code:

Code:
ssh user@host 'myvar=`egrep -i "ERROR|WARNING" /some/folder/test.txt`; echo $myvar; if [ $myvar=WARNING ]; then echo "dit is een WARNING"; elif [ $myvar=ERROR ]; then echo "ERROR foutjeu"; else echo "niks aan de hand"; fi'
but when i run it, i get a WARNING (from the echo) but in the file that i'm checking isn't a warning written..

UPDATE:
i've changed my code to this:
Code:
ssh user@host 'myvarE=`grep ERROR /some/folder/test.txt`; echo $myvarE; myvarW=`grep WARNING /some/folder/test.txt`; echo $myvarW; if [ $myvarW=WARNING ]; then echo "dit is een WARNING"; else echo "niks aan de hand"; fi; if [ $myvarE=ERROR ]; then echo "ERROR foutjeu"; else echo "niks aan de hand"; fi'
and this is my result:
Code:
ERROR                                  -> GOOD

dit is een WARNING
ERROR foutjeu
I've put in the file an ERROR (so he shows it first). but then when he gets to the IF statements, he just gives me the result of an ERROR AND a WARNING...
am i missing something?

and when i put nothing of error or warning in the test.txt file, i still get the 2 messages...
i don't understand why, in my opinion i did everything right?

Last edited by brownie_cookie; 03-25-2011 at 08:47 AM.
 
Old 03-25-2011, 08:59 AM   #39
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
it's working ;-)

Code:
ssh user@host 'myvarE=`grep "ERROR" /some/folder/test.txt`; echo $myvarE; myvarW=`grep "WARNING" /some/folder/test.txt`; echo $myvarW; if [ "$myvarW" = "WARNING" ]; then echo "dit is een WARNING"; else echo "niks aan de hand"; fi; if [ "$myvarE" = "ERROR" ]; then echo "ERROR foutjeu"; else echo "niks aan de hand"; fi'
UPDATE:
Code:
ssh user@host 'myvarE=`grep -i "ERROR" /some/folder/test.txt`; echo $myvarE; myvarW=`grep -i "WARNING" /some/folder/test.txt`; echo $myvarW; if [ "$myvarW" = "warning" ] || [ "$myvar" = "WARNING" ]; then echo "dit is een WARNING"; else echo "niks aan de hand"; fi; if [ "$myvarE" = "error" ] || [ "$myvar" = "ERROR" ]; then echo "ERROR foutjeu"; else echo "niks aan de hand"; fi'
the problem now is that when i use 'error' or 'warning' (low case) it works just fine, but when i use 'ERROR' or 'WARNING' (high case) it doesn't work...
how come? does anyone know?

Last edited by brownie_cookie; 03-25-2011 at 09:53 AM.
 
Old 03-25-2011, 10:14 AM   #40
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

Sorry I couldn't pay any attention earlier, I've been a bit tied up at work with some serious problems. Have a look at the man page for grep. The -i option stands for
Code:
-i, --ignore-case
              Ignore  case distinctions in both the PATTERN and the input files.  (-i is specified by
              POSIX.)
Glad to hear you've gotten closer to your solution.

Kind regards,

Eric
 
Old 03-28-2011, 01:08 AM   #41
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
no problem ;-)
the weekend has past, it's time to get back to work ;-)

i am going to figure it out what the problem is, why his working fine with the lowercase but not with the other..

i'll keep you posted
 
Old 03-28-2011, 01:12 AM   #42
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

Looking forward to your feedback. Have a good one.

Kind regards,

Eric
 
Old 03-28-2011, 02:27 AM   #43
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
This is the code:

Code:
#!/bin/bash

ssh user@host 'echo "hallo, $USER"'
ssh user@host 'echo'
ssh user@host 'myvarE=`grep -i "ERROR" /some/folder/test.txt`; echo $myvarE; myvarW=`grep -i "WARNING" /some/folder/test.txt`; echo $myvarW; if [ "$myvarW" = "warning" -o "$myvarW" = "WARNING" ]; then echo "dit is een WARNING"; else echo "niks aan de hand"; fi; if [ "$myvarE" = "error" -o "$myvarE" = "ERROR" ];then echo "ERROR foutjeu"; else echo "niks aan de hand"; fi'
ssh user@host 'echo dit is een test'
and surprise surprise, it works ^^
now i need to make a lot more code to test all the different folders/files

but i have another question.. is theire a command to check on timestamp?
because i need to check some files to see how old they are; e.g. if a file is older than 15 minutes i need to get a warning

thx ^^
 
Old 03-28-2011, 02:41 AM   #44
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

You can use the find command with parameters (from the man page)
Code:
-amin, -atime, -cmin, -ctime, -mmin, and -mtime
for your different needs. If you don't want to use find you can use ls with
Code:
-c     with -lt: sort by, and show, ctime (time of last modification of file status information) with -l: show ctime and sort by name otherwise: sort by ctime
Lots of commands have a parameter you can use to sort/find by time, so have a look at the man page of the command you want to use or are familiar with.

Kind regards,

Eric
 
Old 03-28-2011, 02:46 AM   #45
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
ok, change of plans...

EDIT:
the person who is guiding/helping me (don't know the english word for that ) came up with an idea!!
he suggested that i make the control-scripts in seperated scripts (without ssh) on the local server
than with another script, i use a SCP to copy them from the local to the remote server and than i execute those copied control-scripts

that's probably the most efficient way to keep everything overviewable (euhhh don't know if that is a real word)

Last edited by brownie_cookie; 03-28-2011 at 02:55 AM.
 
  


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
Can't SSH to remote machine: Connection closed by remote host Avatar Linux - Networking 34 05-24-2013 09:28 AM
Fedora 10/unable to ssh out from box to remote host (SSH within LAN ok) huskeypm Linux - Networking 3 04-14-2009 07:37 PM
SSH - Remote aplications in remote server Urien Linux - Newbie 11 04-04-2009 04:02 AM
Remote login with SSH, but display on remote computer. brodin Linux - Software 3 09-09-2007 03:01 AM
Remote SSH Kurzweil Linux - Newbie 23 05-14-2005 12:41 AM


All times are GMT -5. The time now is 09:25 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration