Simple SSH script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple SSH script
# 1  
Old 11-05-2009
Simple SSH script

I have several unix servers,
I need to logon to each server and find out if an id exists on that server.
I need a simple script for this, i have come up with the following script, but I cannot bring the output of a child process on the remote server.
HTML Code:
for i in `cat SERVER_LIST`
do
ssh $i <<EOF>> server_idchk4user_$sysid.log
id $1
if [ $? = 0 ];then
echo "I have a login on $i server"
else
echo "I do not have a login on $i server"
exit
EOF
done


Any help s greatly appreciated.
# 2  
Old 11-06-2009
Why login?

You can run commands on the remote machines without logging in through a script.

Code:
ssh myacct@machine id
echo $?
0
ssh noacct@machine id
echo $?
255

# 3  
Old 11-06-2009
Thanks for the reply Tony!

I wanted to enhance the script in future,
saylike i needed to know what sudo privileges does the id have on remeote machine, that is why I wanted to login thru a script

there are several issues, I'm describing them down here.

1) there are like 300 servers in the SERVER_LIST file.On each server I should find if an ID exists or not.

2) Everytime the script executes It prompts me for a password. How to overcome this, I tried it with expect, but have no experience using expect.

3) ssh noacct@machine id
It prompts for a password again and again, I cannot execute echo $? (since its prompting for password again and again)

Thankyou for the help. I greatly appreciate.
# 4  
Old 11-06-2009
ssh keys are your friend. If you have 300 servers though thats going to take some work to get them setup though.
# 5  
Old 11-06-2009
Quote:
Originally Posted by ramky79
2) Everytime the script executes It prompts me for a password. How to overcome this, I tried it with expect, but have no experience using expect.
I agree with ssh keys. I set up my first auto-login script last night using this site as reference. It's really easy, but I was doing it on 298 less computers..
# 6  
Old 11-09-2009
Also: if you are going to be doing a lot of this, you might look at "expect" - not for logging in (ssh keys is the right choice there) but for handling more complex situations after login.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies

2. Shell Programming and Scripting

Can't solve a simple SSH/scp issue.. Please help.

Disclaimer: I tried searching but wasn't able to get to the answer so please don't flame. Scenario: I have a root script that generates a file on box1 and then needs to scp it over to box2 using user1. Both boxes are running open-ssh. root@locat-host# scp /tmp/file1 user1@box2:/tmp/file1 ... (10 Replies)
Discussion started by: denissi
10 Replies

3. Shell Programming and Scripting

Simple if script

Hi, new to unix and scripting, and i'm trying to set up a simple "if" script to create a seperate flag file dependant on success. So far i have the following ($5 is a variable passed to the script from the backup job) if then touch /u03/backups/backup_ended.flag else touch... (13 Replies)
Discussion started by: richs24
13 Replies

4. Linux

How to execute a simple select script using a shell script?

Hi team, I have two select statements and need to run them using SYSDBA user select * from temp_temp_seg_usage; select segment_name, tablespace_name, bytes/ (1024*1024) UsedMb from dba_segments where segment_name='TEMP_TEMP_SEG_USAGE'; Need to run this using a shell script say named... (1 Reply)
Discussion started by: pamsy78
1 Replies

5. Shell Programming and Scripting

Simple script need help

Hi Gurus, I have a requirement which need copy some files and rename them in same dir. for example I need to rename all files with ABC at begining of file name. #! /bin/ksh filelist=`ls ABC*` while read file do echo ${file: 0:18} cp $file ${file: 0:18} done <"${filelist}" i got... (7 Replies)
Discussion started by: ken6503
7 Replies

6. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

7. Shell Programming and Scripting

Simple Script to do so?

hi guys, i am a noob to shell scripting, and i would like to run a simple script, that could simply do the following: 1. SFTP to a remote server/path...and download the newest *.gz backup file on that server. (there are many *.gz files in that folder, i simply need the latest one) 2. locally... (1 Reply)
Discussion started by: Confidence
1 Replies

8. Shell Programming and Scripting

Need to create a simple script using MD5, SSH...

Hi all, I am brand new to these forums and I am a brand new UNIX Administartor. Don't know any scripting yet :wall:, and would like to learn as my boss is slowly letting me understand everything about being a Sys/*Nix Admin. He created this script which I am trying to replicate because I lost it... (54 Replies)
Discussion started by: zixzix01
54 Replies

9. UNIX for Dummies Questions & Answers

simple script

how do i put a date to the tar file in my script (9 Replies)
Discussion started by: phehaM
9 Replies

10. UNIX for Dummies Questions & Answers

Simple script

I am trying to print my script arguments, but i am stuck at the arrow pointed lines..please help #!/bin/bash echo "Number of arguments $#" count=1 while do echo ${$count} <======================== count = $(expr $count +1) <================== done (4 Replies)
Discussion started by: chvs2000
4 Replies
Login or Register to Ask a Question