Script for login to servers with user name and password and execute commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for login to servers with user name and password and execute commands
# 1  
Old 07-10-2012
Script for login to servers with user name and password and execute commands

I am having the 15 servers which need to do the monitoring
Hi I need a shell script, By which i can log in to multiple servers and execute the commands.. I need to specify the username and password in the scripts.

Please help me to write the script so that it can login with username and password and execute the commands and generate the report.

It would be greate if anyone give me the sample script so that I can modify as per my requirements

Thanks in Advance

Regards
Nandan
# 2  
Old 07-10-2012
How do you connect? ssh, telnet, or ?
# 3  
Old 07-10-2012
ssh.

I need to specify the password in the script itself.
# 4  
Old 07-10-2012
You cannot do that. You need to create ssh keys, which is VERY EASY to do.

ssh-keygen: password-less SSH login

Then you can do something like this:
Code:
for i in server1 server2 server3
do
  ssh $i 'command to do something on each server goes here'
done

# 5  
Old 07-10-2012
Thanks for the reply. But I do not want to create the ssh key.

I need to pass the password in the script itself.
# 6  
Old 07-10-2012
ssh, and any other sane login system, is designed to prevent you from injecting plaintext passwords. "interactive password authentication" means "password typed by a human being in realtime authentication" and nothing else will do. It reads from a terminal to make sure it's getting human input and not scripted input.

It's a subtle hint, written in mile-high flashing neon letters, that scripting passwords is an extremely bad idea. It's insecure. That's why they made it so hard to do.

Fortunately ssh has the simple, easy, and convenient ssh-keys feature built into it for you to use. Just have the right files in the right places and it will work natively.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to set user password to never expire in UNIX servers

Hi, I have a requirement where in i need to write a shell script to set users password to never expire. I know the command which is used to perform the same .. which is chage command. But, could not figure out how to do the same in shell script. Could you please help me with the shell... (3 Replies)
Discussion started by: suren424
3 Replies

2. Solaris

How can i setup ssh password-less login for particular user?

HI Community. I was trying to create ssh password less authentication for one user called night and it's not working for me. These are the steps I followed:- I have logged into the server and issued ssh-ketgen -t rsabash-3.2$ ssh-keygen -t rsa Generating public/private rsa key pair.... (4 Replies)
Discussion started by: bentech4u
4 Replies

3. Shell Programming and Scripting

Login to remote host and execute commands

Hi, i want to write script where it will login into 50 hosts and if login is successful it print message "login to host1 is successful" if not it should print message "Not able to login to host1". once connection to the host is succesful it should fire df command to check filesystem if df is... (3 Replies)
Discussion started by: amru8810
3 Replies

4. Shell Programming and Scripting

Script to execute command to get info from multiple servers

Hi, I want to collect info from a no. of servers whether there grub.conf contain "elevator" parameter or not. What I want is sudo cat /etc/grub.conf | grep -q "elevator=noop"; echo $? If output is "0", I want name of that host in a file called "present" if its not "0", I want that... (4 Replies)
Discussion started by: stunn3r
4 Replies

5. Shell Programming and Scripting

How to take input from the user from the command line and execute commands basedon that?

Hi, I am using solaris 10 and bash shell.Script execution follows below.Initially it will check whether a directory exists or not if does not exist it will create it.(This I have completed) Second step:I have four users say user1,user2,user3,user4.Script should prompt for the user id and... (11 Replies)
Discussion started by: muraliinfy04
11 Replies

6. Shell Programming and Scripting

connect to multiple servers using SSH and execute commands

Requirement: Run a shell script with below inputs file name checksum path the script should go to multiple servers (around 35) and verify the input cksum and if there is a mismatch display a simple message to the user that cksum verification failed. host details, user id /... (1 Reply)
Discussion started by: amicableperson
1 Replies

7. Shell Programming and Scripting

How to give user name and password in a single command to login to remote server

Hello All, I'm new to unix and i need the below favour from you. I have list of 50 unix server. I need to login to all the server one by one and with the same user and password. I will declare the user name and password globally in the script. for example : servername- hyperV user name... (4 Replies)
Discussion started by: Hari A
4 Replies

8. Debian

password less login to root from a user account

hello friends, one user is created named "user1" I login as "user1" . Now when i do "su -" to be root user I have to give password for root . Is there any way through which we can skip giving the password to root. i.e. user1@work:~$ su - Password: xxxxxx work:~$ I don't want that... (1 Reply)
Discussion started by: pradeepreddy
1 Replies

9. Shell Programming and Scripting

login into root from user and execute command through script

i have logged in as user. I want to write a script to login into root and execute commands for eg. ifconfig or other command. kindly help me out. (6 Replies)
Discussion started by: pradeepreddy
6 Replies

10. Shell Programming and Scripting

How to restrict the number of commands user can execute

Hi all, Is there a way to prevent users from being able to execute commands less a select few? For instance, I wish to allow the user to be only able to execute 1 command, which is exec a.sh. He should not be able to do simple stuff such as ls, cd, rm, cat, etc. Can this be achieved? ... (1 Reply)
Discussion started by: rockysfr
1 Replies
Login or Register to Ask a Question