Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
#!/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
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 04:07 AM.
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:
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?
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
Hi,
You're welcome. You mean graduating instead of educating right?
Just edited my post and removed user and hostname.
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.
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).
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.
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:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.