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.
I'm kinda new to linux and stuff.
I'll try to explain what the situation is:
i need to connect to a remote linux server on certain times (automated), but i need to log on to the server. So i want to make a script (shell perhaps) that periodically connects to the server and checks some files and folders.
How do i automate it and how can i log on automatically to the remote server without typing everytime the password and login (the script should do it himself)
i hope that you'll understand what i'm saying (my english is not that good).
pls help me ^^
grtz
cookie
Click here to see the post LQ members have rated as the most helpful post in this thread.
You can use key instead of password authentication as explained for example for Debian (since you didn't mention your distro) on this site. Another option is to use a program like sshpass to provide the password to ssh on the commandline or in a script for that matter. I'm assuming you'll be connecting from a Linux machine to a SSH server. If you connect from your Windows machine then other paths will need to be followed.
Hi all
I'm kinda new to linux and stuff. I'll try to explain what the situation is:
i need to connect to a remote linux server on certain times (automated), but i need to log on to the server. So i want to make a script (shell perhaps) that periodically connects to the server and checks some files and folders. How do i automate it and how can i log on automatically to the remote server without typing everytime the password and login (the script should do it himself)
i hope that you'll understand what i'm saying (my english is not that good).
pls help me ^^
grtz
cookie
Please spell out your words...your English is very good, but text-speak is never easy (or good) to read/post in.
What you want is to do an SSH keyswap, so that the account on your local system can attach to the remote system, without putting in a password. This will keep you from having to put a password in a script (which is unsafe), but still let things be secure. There are many how-tos available on how to do this, but essentially, it's just running (as the user you want to use to automate things):
[LOCAL] ssh-keygen -t rsa (take the defaults for everything)
[LOCAL] cd $HOME/.ssh
[LOCAL] cp id_rsa.pub authorized_keys2
[LOCAL] scp authorized_keys2 <user ID>@<remote system IP>: (have to enter a password this time to make the copy work)
:: log in to remote system, run first three local steps above. ::
[REMOTE] cat ../authorized_keys2 >> authorized_keys2 (you copied the authorized_keys2 file from the other system to the home directory eariler, now you're appending it to the remote-systems authorized users file)
:: log out ::
Now, when you use that user ID to SSH again, it shouldn't prompt you for a password, just attach, since you did a key-exchange. You can use "expect" in a script, too, but it's insecure, since the password/ID will be in clear-text in the script.
the matter of secure or not, doesn't really matter.
i just need to log on from a pc (or server) to a remote server where i need to log on and when i'm logged on, i need to check files.
I'm doing that with Centreon/Nagios (maybe someone has experience with that?)
Everything you guys suggested as solutions, i will try (tomorrow, because it's almost time to go home ).
And when i have tested it, i will post you back.
But can anyone of you tell me, all the things you say, can i put it in ONE shell script?
the matter of secure or not, doesn't really matter.
i just need to log on from a pc (or server) to a remote server where i need to log on and when i'm logged on, i need to check files.
I'm doing that with Centreon/Nagios (maybe someone has experience with that?)
But can anyone of you tell me, all the things you say, can i put it in ONE shell script?
Hello,
You're welcome. You'll find that LQ users are very numerous and there's always more then one member that can help out.
Believe me, if you'll be connecting to remote servers over the internet, you WILL need to take care of security whenever and wherever you can. It's better to prevent then to be sorry. Since you'll be connecting to someone else's server you need to make sure that you're not the cause of their system breaking, for which they in turn could accuse you. It doesn't cost anything, neither money nor time to set up a secure connection for you to use.
Lot's of experience with Nagios here on LQ, just depends on the question how soon you'll get a solution
Almost anything, if not everything, can be put in a script in one way or another to automate things. Just be a bit more detailed of what you need to do, what you've got and what you're missing and we'll take it from there. You will have to put in some time of yourself since ready made solutions hardly ever get offered here at LinuxQuestions.
You're welcome. You'll find that LQ users are very numerous and there's always more then one member that can help out.
Believe me, if you'll be connecting to remote servers over the internet, you WILL need to take care of security whenever and wherever you can. It's better to prevent then to be sorry. Since you'll be connecting to someone else's server you need to make sure that you're not the cause of their system breaking, for which they in turn could accuse you. It doesn't cost anything, neither money nor time to set up a secure connection for you to use.
Lot's of experience with Nagios here on LQ, just depends on the question how soon you'll get a solution
Almost anything, if not everything, can be put in a script in one way or another to automate things. Just be a bit more detailed of what you need to do, what you've got and what you're missing and we'll take it from there. You will have to put in some time of yourself since ready made solutions hardly ever get offered here at LinuxQuestions.
Kind regards,
Eric
You couldn't have said that any better. +1 to that...
You're welcome. You'll find that LQ users are very numerous and there's always more then one member that can help out.
Believe me, if you'll be connecting to remote servers over the internet, you WILL need to take care of security whenever and wherever you can. It's better to prevent then to be sorry. Since you'll be connecting to someone else's server you need to make sure that you're not the cause of their system breaking, for which they in turn could accuse you. It doesn't cost anything, neither money nor time to set up a secure connection for you to use.
Lot's of experience with Nagios here on LQ, just depends on the question how soon you'll get a solution
Almost anything, if not everything, can be put in a script in one way or another to automate things. Just be a bit more detailed of what you need to do, what you've got and what you're missing and we'll take it from there. You will have to put in some time of yourself since ready made solutions hardly ever get offered here at LinuxQuestions.
Kind regards,
Eric
Thanks ^^ this is actually one of the FEW forums that they are so kind (maybe i have been on the wrong fora, but nevermind)
Oke, security is maybe a nice thing to have, but i'm still on the testing environment, so it is at the moment not the main issue.
What i need to do:
I need to find (or make) a script (preferable in shell) that connects from server A to server B.
When the script wants to connect to server B, it needs to login (without a person that types in the requirements), so it needs to login automatically.
When it succeeded, then the script needs to check folders (like /some/folders/needed/to/be/checked), it has to check how long a file/folder has been there and it needs to check other files that theire is a line with ERROR or WARNING in it.
When that is the result, i (or another person) needs to get an notification (e-mail/sms/...).
And all of this need to be done at certain times, so at e.g. 14h a script needs to be launched (automatically) to check my objectives (but i geuss that can be done with a cronjob).
All of this i need to do with Centreon/Nagios.
So the notification will be done by Centreon, but i need to have some kind of script that check my objectives. Now, i know that theire are plugins for nagios, that control these things (folder age, file checking, ...) but these plugins are mostely for localhost folders/files.
I also know that there are plugins to check REMOTE for folders/files, but they have a problem and that is that they don't have the possibility to log on to my remote server.
I hope you guys understand my problem and i really hope you guys can help me ^^
Thx
brownie_cookie
Last edited by brownie_cookie; 03-25-2011 at 02:18 AM.
That is indeed important to know that you're in a testing environment, but practice makes perfect I'd advice you to use security even in a testing environment to get familiar with it. Now for your question.
You can write your own script that can do whatever you need/want. Pointers are given in previous posts on how to use keys to authenticate or software to provide a password to your ssh command. You want to use it (your script) as a Nagios plugin so that you can use Nagios to execute the monitoring? Then adapt your script to do just that. No need for a cronjob in that setup since Nagios will take care of both execution and notification if configured correctly.
Now, this is the time where I (and most LQ users too) will ask you to show us what you've got and where it's failing or where you're in doubt. You're the one who will have to put in the work , LQ will provide answers where you're doubting.
I tried yesterday some things with private and public keys, it kinda worked, but i will found my problem.
The main problem is, i don't have a clue how to start with the script.
I thought the first step would be: connecting to the server
step two: trying to find the right folders
step three: controlling the folders/files
step four: give some feedback
i have no experience with shell . But can i search folders (with shell) in a windows-like environment?
I going to test now the connecting to the server with the preview posts.
Those will get you started and are a great source of knowledge.
Basically, you need to be aware that your script will depend on you making it 'not needing user input'. As always there are various ways to obtain what you need. For example to execute a command on a remote server through SSH you can use a line like this:
Code:
ssh <user>@<host> '<command to execute on remote server>;<other command on remote server>'
The output will be shown on your terminal, so you can easily redirect it in your script to a variable or a file, whatever you need. The above command works without you providing a password if you've set up key authentication. If you haven't set up key authentication and need to pass the password you could use sshpass to do so. Be aware though that your password will be in plain text in the script.
Code:
sshpass -p 'yourpassword' ssh <user>@<host> '<command to execute on remote server>;<other command on remote server>'
I'd first write your basic script if you don't have experience with Nagios plugins and 'adapt' it to Nagios later on.
First step would be to decide which way you will authenticate. Set that up and test it. Then experiment with the ssh command as pointed to before, running commands on remote servers. If you're familiar with that, start with your script and test every command you put in it on the console to check if it works the way you want it to.
thanks for the links!! i will sure look at them when i the authentication is working.
Now i am trying to let the authentication work, but i have a problem (again )...
I am using these steps of an earlier post:
* [LOCAL] ssh-keygen -t rsa (take the defaults for everything)
* [LOCAL] cd $HOME/.ssh
* [LOCAL] cp id_rsa.pub authorized_keys2
* [LOCAL] scp authorized_keys2 <user ID>@<remote system IP>: (have to enter a password this time to make the copy work)
* :: log in to remote system, run first three local steps above. ::
* [REMOTE] cat ../authorized_keys2 >> authorized_keys2 (you copied the authorized_keys2 file from the other system to the home directory eariler, now you're appending it to the remote-systems authorized users file)
* :: log out ::
Everything is going fine, until i get to the step number 6. when i do this command i get an error like this:
cat: Cannot open ../authorized_keys2: No such file or directory
but the first part of the command (cat ../authorized_keys2) is that of the local server?
so if i'm getting it right about the ssh-keyswap.
As long as i keep those files (id_rsa, id_rsa.pub and authorization_keys2) on both sides (local and remote) i can log on perfectly at the remote side?
the name authorization_keys2, can i choose another name, or must it be that name?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.