Sponsored Content
Full Discussion: While true loop stopped
Top Forums Shell Programming and Scripting While true loop stopped Post 303027755 by bakunin on Sunday 23rd of December 2018 08:57:05 AM
Old 12-23-2018
Quote:
Originally Posted by sadique.manzar
My script condition on connection refused have break command.
To be honest i fail to see a justification for the break reserved word here. The purpose of break is to get out of loops like this:

Code:
while <condition> ; do
     something
     if <other-condition> ; then
          break
     fi
done

Which will cause the while .. do....done to be left when "other-condition" is met. Still, break (as well as its companion continue) should be used with extreme care or rather be avoided in most cases. They both are in fact thinly veiled GOTOs and there is a reason why structured programming languages without GOTOs were invented - it simply makes the task of keeping up with understanding (your own) code and the program flow a lot easier.

So, let us take a step back: what are you trying to achieve? State a clear and complete problem and we sure can work out a solution which does not depend on break or similar constructs.

Another possibility is: ssh allocates a terminal and therefore captures <stdin> - as does while. Alas, what one usually experiences is not that it fails permanently but a rather inconsistent behavior of "sometimes it works, sometimes not". Might it be that this is the case here?

I hope this helps.

bakunin

PS: on second thoughts, you should also get rid of the echos and the backticks - both are antiquated, deprecated and not best practice for quite some long time now.

bakunin
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

True Shutdown help!

ok, i know the syntax that goes along with the Shutdown command... but my box never wants to ... well... shutdown.. it only halts, kills all the process's, stalls the comp to a complete stop, but does actually kill the monitor and/or shut off the physical computer. it will reboot properly though,... (3 Replies)
Discussion started by: 01000101
3 Replies

2. UNIX for Dummies Questions & Answers

is it true or not

I have heard for a long time that in maybe 2039 Unix will no longer be useable due the length of the date value. Anyone know anything about this? (4 Replies)
Discussion started by: dhlopomo
4 Replies

3. Shell Programming and Scripting

how to exit a while true loop

Hi guys, I'm new to unix but loving it!! BUT this is driving me nuts as i can't work out the best way to do it. I have a while true loop that i use to monitor something. For my own reasons in ths script i have disabled the CTRL C using the trap command. But i want to put in a option to exit... (5 Replies)
Discussion started by: Noob e
5 Replies

4. Shell Programming and Scripting

Bash: Exiting while true loop when terminal is not the focus window

I am running an Ubuntu Gutsy laptop with Advanced Compiz fusion options enabled. I am using xdotool to simulate keyboard input in order to rotate through multiple desktops. I am looking for a way to kill a while true loop when the Enter key (or Control+C if it is easier) is pushed when the... (2 Replies)
Discussion started by: acclaypool
2 Replies

5. UNIX for Dummies Questions & Answers

Funny but true....

Hallo everybody I am having a shell script called auto_run.sh in that only the first line works. the second line which has sed command is working only at the # prompt. not within the shell script. What could be the reason. *... sed 's/ //g' KTI >abc works in another shell script without the... (6 Replies)
Discussion started by: naushad
6 Replies

6. UNIX for Dummies Questions & Answers

stopped processes

When I try to exit a session, the message 'there are stopped processes' appears and I can not log out? Solution, please? (2 Replies)
Discussion started by: operag
2 Replies

7. Shell Programming and Scripting

loop until true

Hi I need help with a script to loop unitl the statement is true done some thing like this until if then cp filename filename.anto fi done Regards, (3 Replies)
Discussion started by: antointoronto
3 Replies

8. Shell Programming and Scripting

Scripts stopped in the shell

Hi, I've been wondering about this for a while and I just don't know where to start looking. Some of my scripts always get stopped when I start them with $ script.plx &in the shell (bash, on Debian lenny, logged in via ssh from a Mac OS machine using Terminal.app). After a few seconds I keep... (4 Replies)
Discussion started by: mregine
4 Replies

9. Shell Programming and Scripting

While loop true problem

hi, i am new in bash scripting. i am trying to write a Bash script to monitor how many process are running in my Redhat6 Linux machine. example : let say there must be always 5 process from the same kind that must run and if one off them fails down the script must wake up another process... (2 Replies)
Discussion started by: zigizag
2 Replies

10. Shell Programming and Scripting

Explaination on if true

Hi Team, I need to know why ppl use If true loop instead of just writing down the sequence of code lines. 1: echo "Line1" if true; then echo "Line2" fi echo "Line3" 2: echo "Line1" echo "Line2" echo "Line3" Could you explain what does the if true loop make difference in 1st compare... (3 Replies)
Discussion started by: chandana hs
3 Replies
SSH-ARGV0(1)						    BSD General Commands Manual 					      SSH-ARGV0(1)

NAME
ssh-argv0 -- replaces the old ssh command-name as hostname handling SYNOPSIS
hostname | user@hostname [-l login_name] [command] hostname | user@hostname [-afgknqstvxACNTX1246] [-b bind_address] [-c cipher_spec] [-e escape_char] [-i identity_file] [-l login_name] [-m mac_spec] [-o option] [-p port] [-F configfile] [-L port:host:hostport] [-R port:host:hostport] [-D port] [command] DESCRIPTION
ssh-argv0 replaces the old ssh command-name as hostname handling. If you link to this script with a hostname then executing the link is equivalent to having executed ssh with that hostname as an argument. All other arguments are passed to ssh and will be processed normally. OPTIONS
See ssh(1). FILES
See ssh(1). AUTHORS
OpenSSH is a derivative of the original and free ssh 1.2.12 release by Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. Jonathan Amery wrote this ssh-argv0 script and the associated documentation. SEE ALSO
ssh(1) Debian Project September 7, 2001 Debian Project
All times are GMT -4. The time now is 10:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy