Visit Our UNIX and Linux User Community


How to write a script to run without password on a batch of servers?


 
Thread Tools Search this Thread
Operating Systems AIX How to write a script to run without password on a batch of servers?
# 1  
Old 09-17-2013
How to write a script to run without password on a batch of servers?

I need run a command such as ps -ef |grep xxx on a batch of servers, how to write a script to run it without password? don't need go in each server to check?

Thanks
# 2  
Old 09-17-2013
Use a PPK Key with ssh -- password-free access to all hosts. The tool 'parallel' can manage the list.
# 3  
Old 09-17-2013
To run remote programs without a password, presumably over ssh, you will need to arrange passwordless logins first.
# 4  
Old 09-17-2013
I usually get it running for 'ssh localhost pwd' first, then copy the entire .ssh* directory to target hosts with 'scp -r'. The localhost entry will be wrong everywhere else, of course.
# 5  
Old 09-19-2013
First thing is to setup rlogin or ssh. I prefer to use ssh.

This is a little script to get you started.

Code:
#!/bin/ksh

HOSTLIST="<LIST OF HOST>"
DELAY=1
print -n Enter Command to process on remote Host -
read CMD
print
exec 4>&1

for HOST in $HOSTLIST ; do
echo "running ${CMD} on ${HOST}:"
ssh -t -t $HOST >&4 2>/dev/null |&
sleep $DELAY
print -p /usr/bin/nohup ${CMD}
sleep $DELAY
print -p exit
wait
echo "${CMD} completed on ${HOST} !"
done

exit 0

# 6  
Old 09-19-2013
techy1: Why not just ssh username@host /usr/bin/nohup $CMD & ? That way you don't need to print into it using coprocess facilities...
# 7  
Old 09-19-2013
that would work. I'm not all that great at writing scripts. just know enough to get by =)

Previous Thread | Next Thread
Test Your Knowledge in Computers #717
Difficulty: Medium
A universal Turing machine can calculate any recursive function, decide any recursive language, and accept any recursively enumerable language.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A script to change password for all other servers

Hey Gurus, I have this requirement to change the password for other servers remotely from one server. So, I installed public keys on all servers and wrote the following script to do the job. Something appears to be wrong with my loop, as it only changes one server and ignores the rest. I'm... (24 Replies)
Discussion started by: Hiroshi
24 Replies

2. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

3. Shell Programming and Scripting

Need to run the batch script from shell scripting

Hi All, I am working on shell scripting.My script is completed but I have one task that is to trigger the batch script(with or without parameter) from my shell scripting(reside on linux system) and output which is geneareted by the batch should e.g. if batch script creates any files then I want... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

4. Shell Programming and Scripting

To run a shell script in remote server from windows batch file

Hi all, i need to run a shell script on remote server. I have created file .bat file in windows server with following code, c:\Users\Desktop\putty.exe -ssh -pw password user@server ./script.sh i need to run the script.sh in my remote server Above command is not working, any... (4 Replies)
Discussion started by: rammm
4 Replies

5. Shell Programming and Scripting

Batch script to run in SFTP

Hello Guys, I am writting a script which is SFTPing from Solaris to Windows. I need to run a Batch script in SFTP session (ongoing) which will map a network drive and then transfer my files. I can run the Batch script via SSH but not via SFTP and this mapping is limited to that SSH... (4 Replies)
Discussion started by: Deei
4 Replies

6. Shell Programming and Scripting

How to run a script using batch file?

the manual process which we follow is login to remote unix box thro putty using the unix account and password and then sudo to root user. server name:abc@server.com login as:pqrst password:****** $ sudo su - root then run the script stored on remote server under root account. ... (9 Replies)
Discussion started by: gpk_newbie
9 Replies

7. Shell Programming and Scripting

sftp batch script with password

I am working on a sftp batch script on a Solaris machine and I need to connect using password. This is not an issue when i do it manually but when I want to make this into a script, i find there are no options for password. Can anyone suggest how I can do it with password? I know using keys is... (3 Replies)
Discussion started by: Leion
3 Replies

8. Shell Programming and Scripting

How to run same script on multiples servers

Hi All, I have some script that run some commands and send results to my email. I want to run same script on mulitiple servers. How can I do that. I know there is an option "ssh". But I'm not quite sure how to use it in the script. And also. scripts has some parameters like following, if :... (10 Replies)
Discussion started by: s_linux
10 Replies

9. Shell Programming and Scripting

How to script to logon servers using id and password

Hey.. I am new in scripting.. I know a little bit of scripting.. I am facing some problem.. I need to create a script using which I may log on to a server (e.g. ftp) with ID and password.. thus copy a particular file to a local dir.. the commands required to do that I do know.. I am able to do it... (1 Reply)
Discussion started by: razeeev
1 Replies

10. Shell Programming and Scripting

How to write a Script to run series of batch jobs on unix platform

Im new to unix shell scripting, I have to run batch jobs on unix. for example i have 5 jobs. first 2 can kickoff parallely. after completely finishing the 2 previous jobs the 3 job should kick off..once 3rd is over 4 th and 5th can kick off parallely. Each jobs run for 1 or 2 hours each. How to... (2 Replies)
Discussion started by: venki311
2 Replies

Featured Tech Videos