Sponsored Content
Top Forums Shell Programming and Scripting While loop is causing ssh command to exit from script after first iteration. Post 302949543 by kchinnam on Monday 13th of July 2015 03:26:03 AM
Old 07-13-2015
Don, usually I would be scared to try </dev/null(empty stuff), but I tried, its working,, how is it telling ssh not to use same file descriptor to read serverList?

Aia, changing file descriptor is not working for me..
Code:
#!/bin/bash
while read -u12 server; do
        ssh $server uptime
done 12 < serverList

output:
./test.sh: line 4: syntax error near unexpected token `12'

ssh -n is working for my current script. But I do see myself using ssh in a interactive manner and enter passwords to remote server login.. in that case I guess while can't be an option..

Interestingly when I replaced while with for loop, its working fine.. since my input is simple I can afford, but this is not the right way for complex inputs.

Code:
for server in $(cat $serverList); do
        ssh $server uptime
done

How can tell ssh not to read from serverList file? -u12 trick is not working on SuSE linux 11 I am using..

Last edited by kchinnam; 07-13-2015 at 05:07 AM.. Reason: clarifying
 

10 More Discussions You Might Find Interesting

1. Solaris

SSH doesnt exit properly from command line

I ssh to another server and run a few commands - start a few processes that run on the server. I then type exit - by my command line hangs. I have heard that it is waiting until anything processes you are running complete, but these processes are going to run 24*7*365 so obviously I cant wait.... (4 Replies)
Discussion started by: frustrated1
4 Replies

2. Shell Programming and Scripting

New iteration of for-loop without incrementing?

Another question, is it possible to, in a for-loop incrementing until it reaches a certain number, to have it loop again without incrementing? Just have it drop what it is doing when it reaches this command and start again at the same number it was at? I know I could make a while loop and just... (0 Replies)
Discussion started by: jeriryan87
0 Replies

3. UNIX for Advanced & Expert Users

Multiple ssh, shutdown and exit script

PROBLEM: I need to ssh into multiple remote machines, send a shutdown command and exit. The remote servers will then run their own scripts to gracefully shutdown their applications before shutting down. ONE: This is to be achieved without using public key authentication; this is being avoided... (2 Replies)
Discussion started by: ulemsee
2 Replies

4. Shell Programming and Scripting

howto stop loop iteration

I wonder how to stop further loop iterations when conditions gets false e.g. This file.txt contains the following structure : 1 2 3 4 5 6 7 8 9 10 How to stop iteration when if statement gets false ? for n in `cat file.txt` do if (( n<=5 )) (1 Reply)
Discussion started by: presul
1 Replies

5. Shell Programming and Scripting

while loop stops after first iteration - remote ssh exit command problem?

I have written the following script to update some Debian boxes. #!/bin/bash mxg_hosts_file="/etc/mxg/ssh-hosts" while read line ; do mxg_host="$(echo ${line} | awk -F":" '{print $1}')" mxg_port="$(echo ${line} | awk -F":" '{print $2}')" echo "Connecting and Upgrading... (3 Replies)
Discussion started by: jelloir
3 Replies

6. Shell Programming and Scripting

Do something only that last iteration of loop

I have a script with logic like: my_function() { if mkdir $1 mkdir mydir_${2} else do something else fi } read in list of items while read list do my_function $list `date` done so basically it will make a directory for every name in the list and create a directory with the... (6 Replies)
Discussion started by: glev2005
6 Replies

7. Programming

String array iteration causing segfault

I am populating an array of string and print it. But it going in infinite loop and causing segfault. char Name = { "yahoo", "rediff", "facebook", NULL }; main(int argc, char* argv) { int j = 0; ... (7 Replies)
Discussion started by: rupeshkp728
7 Replies

8. Shell Programming and Scripting

Getting the iteration count in WHILE LOOP

bash in RHEL 6.4 I have a requirement in which I want to get the iteration count from a WHILE LOOP. The below mentioned simple script test.sh works fine. In the below script, the WHILE loop will iterate every 5 seconds infinitely until it greps the string BASKETBALL from /tmp/somestring.txt... (6 Replies)
Discussion started by: John K
6 Replies

9. Shell Programming and Scripting

Loop iteration with two variables

Hello, I have been stuck on this for some time and invested many hours trying to find a solution. I am trying to either loop through two variables or or two arrays and not sure how to do it. I am limited to ksh only, and don't have the ability to do a foreach, or for i AND for j etc...I... (19 Replies)
Discussion started by: Decoy Octopus88
19 Replies

10. Shell Programming and Scripting

While loop is running only for the first iteration

Hello, I've written a script to automate encoding of all the MP4 files in a directory (incl. subdirectories). But unfortunately it's running for the first MP4 file only. My machine details: root@Ubuntu16:~# uname -a Linux Ubuntu16 4.10.0-28-generic #32~16.04.2-Ubuntu SMP Thu Jul 20 10:19:48... (2 Replies)
Discussion started by: prvnrk
2 Replies
RPC.YPPASSWDD(8)					    BSD System Manager's Manual 					  RPC.YPPASSWDD(8)

NAME
rpc.yppasswdd -- NIS update password file daemon SYNOPSIS
rpc.yppasswdd [-d directory] [-noshell] [-nogecos] [-nopw] [-m arg1 [arg2 ...]] DESCRIPTION
rpc.yppasswdd must be running on the NIS master server to allow users to change information in the password file. The options are as follows: -d directory Change the root directory of the password file from ``/'' to directory. It is important to create the binary database files (pwd.db and spwd.db) when using this switch or the password change will fail. The databases need to be created only once with the following command: pwd_mkdb -d directory directory/etc/master.passwd -noshell Don't allow changes of the shell field in the passwd file. -nogecos Don't allow changes of the gecos field in the passwd file. -nopw Don't allow changes of the password in the passwd file. -m arg1 [arg2 ...] Additional arguments to pass to make in /var/yp. FILES
/etc/passwd /etc/master.passwd SEE ALSO
chpass(1), passwd(1), hosts_access(5), nis(8), ypbind(8), ypserv(8) AUTHORS
Mats O Jansson <moj@stacken.kth.se> BSD
February 26, 2005 BSD
All times are GMT -4. The time now is 10:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy