LinuxQuestions.org
Visit Jeremy's Blog.
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, 04:36 AM   #16
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,

Once the key pair is generated and the public part (.pub) is copied over to the remote server and added to the authorized_keys file you're good to go. As long as your key (id_rsa) coincides with the id_rsa.pub you added on the remote server you have key based authentication.

If you delete either part of the key pair, be it your local file or the public part on the remote server, you'll have to redo the process or at least the part that's missing.

Kind regards,

Eric
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-25-2011, 04:53 AM   #17
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 script i was testing:
Code:
#!/bin/bash
ssh username@hostname

echo "hallo, $USER"
echo

echo "Datum: 'date', week: 'date +"%V"'."
echo

echo "this is 'uname -s' running on a 'uname -m' processor."
echo

echo "uptime:"
uptime
echo
but when i run it with ./test.sh
it logs on to the remote server (good) but then nothing happens, but when i typ exit (to log off), then the script is being run:
output after exit:
Code:
hallo, root

Datum: 'date', week: 'date +%V'.

this is 'uname -s' running on a 'uname -m' processor.

uptime:
 09:50:03 up 2 days, 18:04,  1 user,  load average: 3.40, 3.34, 3.19
also, some command doesn't seem to work?
i found this example with the subject about BASH (i guessed it was the same as shell??)

greetings

---------- Post added 03-25-11 at 09:53 AM ----------

Quote:
Originally Posted by EricTRA View Post
Hi,

Once the key pair is generated and the public part (.pub) is copied over to the remote server and added to the authorized_keys file you're good to go. As long as your key (id_rsa) coincides with the id_rsa.pub you added on the remote server you have key based authentication.

If you delete either part of the key pair, be it your local file or the public part on the remote server, you'll have to redo the process or at least the part that's missing.

Kind regards,

Eric
thx ^^

Last edited by brownie_cookie; 03-25-2011 at 05:07 AM.
 
Old 03-25-2011, 05:02 AM   #18
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,

Read again what I posted before. You need to open a connection for every command. In your script you just open a connection, period. It just sits there waiting until you log out, and then the next lines of your script get executed. What you need to do is execute every command either in a new connection or sequentially in one connection. Try the following:
Code:
#!/bin/bash
ssh user@host 'echo "hallo, $USER"'
ssh user@host 'echo'
ssh user@host 'echo "Datum: 'date', week: 'date +"%V"'."'
ssh user@host 'echo'
ssh user@host 'echo "this is 'uname -s' running on a 'uname -m' processor."'
ssh user@host 'echo'
ssh user@host 'echo "uptime:"'
ssh user@host 'uptime'
or sequentially:
Code:
ssh user@host 'echo "hallo, $USER"; echo; echo "Datum: 'date', week: 'date +"%V"'."; echo; echo "this is 'uname -s' running on a 'uname -m' processor."; echo; echo "uptime:"; uptime'
I've noticed your URL being from an educational institute (VITO) in Belgium (Yeah, I'm Belgian!!). Are you a student and is this homework? You realize that if you are a student and this is homework that your teacher might be looking at LQ too?

Kind regards,

Eric

Last edited by EricTRA; 03-25-2011 at 05:23 AM.
 
Old 03-25-2011, 05:07 AM   #19
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
Thanks ^^

no, it's not homework i'm a stage student. I'm in my final year before educating.
It has been a while that i've been working with shell so...

but can i ask you to edit your post so the link to the remote server isn't visible? (i am going to edit mine)
i don't wont to get any problems
 
Old 03-25-2011, 05:24 AM   #20
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
Quote:
Originally Posted by brownie_cookie View Post
Thanks ^^

no, it's not homework i'm a stage student. I'm in my final year before educating.
It has been a while that i've been working with shell so...

but can i ask you to edit your post so the link to the remote server isn't visible? (i am going to edit mine)
i don't wont to get any problems
Hi,

You're welcome. You mean graduating instead of educating right?

Just edited my post and removed user and hostname.

Kind regards,

Eric
 
Old 03-25-2011, 05:30 AM   #21
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
oke, it's working.

the next step would be, looking for files and searching for words like ERROR / WARNING.
how can i do that?
i propably open them with cat /path/name.log then i would propably put the last line of the file in a variable
and then in some way i have to test the variable

but it's easier to say then to be done

---------- Post added 03-25-11 at 10:31 AM ----------

Quote:
Originally Posted by EricTRA View Post
Hi,

You're welcome. You mean graduating instead of educating right?

Just edited my post and removed user and hostname.

Kind regards,

Eric
thanks and indeed graduating


greetings

brownie
 
Old 03-25-2011, 05:35 AM   #22
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,

Just put the command you want to execute between the '' for the ssh command to pass on to the remote server. Open a connection to your remote server and execute the commands you normally would run and check if the output is correct. Then put that/those commands in the ssh command just like the ones you have in your example.

What do you mean by looking for files? Check for existence, size, modification time? Look at the man page for ls and find.
If you want to 'search' through a file for specific strings, have a look at the man page for grep. Sorry, I posted awk where it should have been grep and didn't realize until you posted.

If you're going to use variables, be careful where you declare them, what you assign to them and where you'll be using the output.

Kind regards,

Eric

Last edited by EricTRA; 03-25-2011 at 05:44 AM.
 
Old 03-25-2011, 05:38 AM   #23
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 need to check in certain folders if they are empty or not and i need to check certain files if they contain an ERROR or WARNING and I need to check certain files for how long they are in some folder (e.g. if a file is longer than 15 minutes in a folder i need to get an error).

i will search the manpages for the command awk !!

thanks

brownie
 
Old 03-25-2011, 05:46 AM   #24
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
Quote:
Originally Posted by brownie_cookie View Post
i will search the manpages for the command awk !!
Hi,

Sorry, I edited my previous post because I pointed you to awk where I wanted to post grep. That happens when one's 'multitasking'.

Kind regards,

Eric
 
Old 03-25-2011, 05:47 AM   #25
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,

Since you're new to Bash, let me point you to this Quick Reference card for Bash. It'll make your life a bit easier I think.

Kind regards,

Eric
 
Old 03-25-2011, 05:49 AM   #26
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 Eric !!
I'm really gratefull that you're helping me ;-)

so i use grep instead of awk?

thnx

brownie
 
Old 03-25-2011, 05:51 AM   #27
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
Quote:
Originally Posted by brownie_cookie View Post
No problem Eric !!
I'm really gratefull that you're helping me ;-)

so i use grep instead of awk?

thnx

brownie
Hi,

Yes, grep is easier to learn then awk and suits your needs perfectly in this case. And you're welcome, you'll find LQ users are of the helping kind

Kind regards,

Eric
 
Old 03-25-2011, 05:55 AM   #28
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Quote:
Originally Posted by EricTRA View Post
Hi,

Yes, grep is easier to learn then awk and suits your needs perfectly in this case. And you're welcome, you'll find LQ users are of the helping kind

Kind regards,

Eric
Sorry to burn you, but awk isn't all that hard. To the OP - With awk, the best way to learn it is to look at the man page... Lots of information within it, and that's how I learned to use it.
 
Old 03-25-2011, 05:57 AM   #29
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
yeah, i've noticed ^^

oke, the grep command does what it needs to do!!
but now i want to put the output of the grep command to be checked.
for instance, if the output is error then i need to get a 1, if the output is an warning i need to get a 0 (zero).

so i think i need to put the output of the grep in a variable ?
i have tried this:
Code:
ssh user@hostname 'grep 'ERROR' /some/dir/test.txt | $test'
ssh user@hostname 'echo $test'
but it doesn't work

or can i do something like:
Code:
if [grep 'ERROR' /some/dir/test.txt == true]; then $VAR == 1;
probably a lot of mistakes in it xD but i'm just thinking 'out loud'

thx
 
Old 03-25-2011, 06:36 AM   #30
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, lots of mistakes

You don't 'pipe' output of a command into a variable. You assign a value to a variable like this:
Code:
VARIABLE=`commmand`
(look at the backticks).
Next, if you assign a value to a variable like you are trying to do in the first ssh command, that variable will not be available in the next connection since it only exists in your first session. If you want to do something like that, look at the second example (how to use sequential commands in one session using ssh).

And don't guess, read the links I pointed you too. That way you'll not only learn something but you'll be aware of what you're doing.

Kind regards,

Eric
 
  


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 35 10-23-2017 01:21 AM
Fedora 10/unable to ssh out from box to remote host (SSH within LAN ok) huskeypm Linux - Networking 3 04-14-2009 08:37 PM
SSH - Remote aplications in remote server Urien Linux - Newbie 11 04-04-2009 05:02 AM
Remote login with SSH, but display on remote computer. brodin Linux - Software 3 09-09-2007 04:01 AM
Remote SSH Kurzweil Linux - Newbie 23 05-14-2005 01:41 AM

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

All times are GMT -5. The time now is 06:44 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration