Skip to main content
added 4 characters in body
Source Link
Nickotine
  • 554
  • 3
  • 17

I have a script which logs in to a server. Regardless of the success (i.e. whether the password is valid or not) the script will exit with return code 0, and the text:

Error login failed.

I'd like it to retry login if this happens by running another command, but because of the return code I can't.

If I pipe the output to grep for 'Error' so I can execute a command based on that then the login dialog doesn't show up in the terminal.

Is there anyway around this?

Pseudo code as this is for work:

loginCmd && echo "$?"
username:
password:

Error login failed. 
0

Update

I tried using an idea from a commentator, but I can't capture the text with 'Error' as that line occurs after the command completes...

Here's what it actually looks like, with incorrect password:

agent registration
username: xyz
password:

Error login failed.

I tried this:

result=$(loginCmd | tee /dev/tty)

grep -q 'Error' <<< "$result" && 
    loginCmd

The error string outputs after the command completes, so result doesn't capture it:

result=agent registration

So I guess there is no way to capture this string?

Error login failed.

Any ideas?

Ideally on login failure the script would return 1, or have some sort of retry mechanism, but it doesn't and I can't change that, it's a company script and this only affects the terminal, not the GUI which is what customers use.

I have a script which logs in to a server. Regardless of the success (i.e. whether the password is valid or not) the script will exit with return code 0, and the text:

Error login failed.

I'd like it to retry login if this happens by running another command, but because of the return code I can't.

If I pipe the output to grep for 'Error' so I can execute a command based on that then the login dialog doesn't show up in the terminal.

Is there anyway around this?

Pseudo code as this is for work:

loginCmd && echo "$?"
username:
password:

Error login failed. 
0

Update

I tried using an idea from a commentator, but I can't capture the text with 'Error' as that line occurs after the command completes...

Here's what it actually looks like, with incorrect password:

agent registration
username:
password:

Error login failed.

I tried this:

result=$(loginCmd | tee /dev/tty)

grep -q 'Error' <<< "$result" && 
    loginCmd

The error string outputs after the command completes, so result doesn't capture it:

result=agent registration

So I guess there is no way to capture this string?

Error login failed.

Any ideas?

Ideally on login failure the script would return 1, or have some sort of retry mechanism, but it doesn't and I can't change that, it's a company script and this only affects the terminal, not the GUI which is what customers use.

I have a script which logs in to a server. Regardless of the success (i.e. whether the password is valid or not) the script will exit with return code 0, and the text:

Error login failed.

I'd like it to retry login if this happens by running another command, but because of the return code I can't.

If I pipe the output to grep for 'Error' so I can execute a command based on that then the login dialog doesn't show up in the terminal.

Is there anyway around this?

Pseudo code as this is for work:

loginCmd && echo "$?"
username:
password:

Error login failed. 
0

Update

I tried using an idea from a commentator, but I can't capture the text with 'Error' as that line occurs after the command completes...

Here's what it actually looks like, with incorrect password:

agent registration
username: xyz
password:

Error login failed.

I tried this:

result=$(loginCmd | tee /dev/tty)

grep -q 'Error' <<< "$result" && 
    loginCmd

The error string outputs after the command completes, so result doesn't capture it:

result=agent registration

So I guess there is no way to capture this string?

Error login failed.

Any ideas?

Ideally on login failure the script would return 1, or have some sort of retry mechanism, but it doesn't and I can't change that, it's a company script and this only affects the terminal, not the GUI which is what customers use.

deleted 11 characters in body
Source Link
Nickotine
  • 554
  • 3
  • 17

I have a script which logs in to a server. Regardless of the success (i.e. whether the password is valid or not) the script will exit with return code 0, and the text:

Error login failed.

I'd like it to retry login if this happens by running another command, but because of the return code I can't.

If I pipe the output to grep for 'Error' so I can execute a command based on that then the login dialog doesn't show up in the terminal.

Is there anyway around this?

Pseudo code as this is for work:

loginCmd && echo "$?"
username:
password:

Error login failed. 
0

Update

I tried using an idea from a commentator, but I can't capture the text with 'Error' as that line occurs after the command completes...

Here's what it actually looks like, with incorrect password:

agent registration
username:
password:

Error login failed.

I tried this:

result=$(loginCmd | tee /dev/tty)

grep -q 'Error' <<< "$result" && 
    loginCmd

result doesn't capture the The error string because the string outputs after the command completes, so result doesn't capture it:

result=agent registration

So I guess there is no way to capture this string?

Error login failed.

Any ideas?

Ideally on login failure the script would return 1, or have some sort of retry mechanism, but it doesn't and I can't change that, it's a company script and this only affects the terminal, not the GUI which is what customers use.

I have a script which logs in to a server. Regardless of the success (i.e. whether the password is valid or not) the script will exit with return code 0, and the text:

Error login failed.

I'd like it to retry login if this happens by running another command, but because of the return code I can't.

If I pipe the output to grep for 'Error' so I can execute a command based on that then the login dialog doesn't show up in the terminal.

Is there anyway around this?

Pseudo code as this is for work:

loginCmd && echo "$?"
username:
password:

Error login failed. 
0

Update

I tried using an idea from a commentator, but I can't capture the text with 'Error' as that line occurs after the command completes...

Here's what it actually looks like, with incorrect password:

agent registration
username:
password:

Error login failed.

I tried this:

result=$(loginCmd | tee /dev/tty)

grep -q 'Error' <<< "$result" && 
    loginCmd

result doesn't capture the error string because the string outputs after the command completes:

result=agent registration

So I guess there is no way to capture this string?

Error login failed.

Any ideas?

I have a script which logs in to a server. Regardless of the success (i.e. whether the password is valid or not) the script will exit with return code 0, and the text:

Error login failed.

I'd like it to retry login if this happens by running another command, but because of the return code I can't.

If I pipe the output to grep for 'Error' so I can execute a command based on that then the login dialog doesn't show up in the terminal.

Is there anyway around this?

Pseudo code as this is for work:

loginCmd && echo "$?"
username:
password:

Error login failed. 
0

Update

I tried using an idea from a commentator, but I can't capture the text with 'Error' as that line occurs after the command completes...

Here's what it actually looks like, with incorrect password:

agent registration
username:
password:

Error login failed.

I tried this:

result=$(loginCmd | tee /dev/tty)

grep -q 'Error' <<< "$result" && 
    loginCmd

The error string outputs after the command completes, so result doesn't capture it:

result=agent registration

So I guess there is no way to capture this string?

Error login failed.

Any ideas?

Ideally on login failure the script would return 1, or have some sort of retry mechanism, but it doesn't and I can't change that, it's a company script and this only affects the terminal, not the GUI which is what customers use.

added 551 characters in body
Source Link
Nickotine
  • 554
  • 3
  • 17

I have a script which logs in to a server. Regardless of the success (i.e. whether the password is valid or not) the script will exit with return code 0, and the text:

Error login failed.

I'd like it to retry login if this happens by running another command, but because of the return code I can't.

If I pipe the output to grep for 'Error' so I can execute a command based on that then the login dialog doesn't show up in the terminal.

Is there anyway around this?

Pseudo code as this is for work:

loginCmd && echo "$?"
username:
password:

Error login failed. 
0

Update

I tried using an idea from a commentator, but I can't capture the text with 'Error' as that line occurs after the command completes...

Here's what it actually looks like, with incorrect password:

agent registration
username:
password:

Error login failed.

I tried this:

result=$(loginCmd | tee /dev/tty)

grep -q 'Error' <<< "$result" && 
    loginCmd

result doesn't capture the error string because the string outputs after the command completes:

result=agent registration

So I guess there is no way to capture this string?

Error login failed.

Any ideas?

I have a script which logs in to a server. Regardless of the success (i.e. whether the password is valid or not) the script will exit with return code 0, and the text:

Error login failed.

I'd like it to retry login if this happens by running another command, but because of the return code I can't.

If I pipe the output to grep for 'Error' so I can execute a command based on that then the login dialog doesn't show up in the terminal.

Is there anyway around this?

Pseudo code as this is for work:

loginCmd && echo "$?"
username:
password:

Error login failed. 
0

I have a script which logs in to a server. Regardless of the success (i.e. whether the password is valid or not) the script will exit with return code 0, and the text:

Error login failed.

I'd like it to retry login if this happens by running another command, but because of the return code I can't.

If I pipe the output to grep for 'Error' so I can execute a command based on that then the login dialog doesn't show up in the terminal.

Is there anyway around this?

Pseudo code as this is for work:

loginCmd && echo "$?"
username:
password:

Error login failed. 
0

Update

I tried using an idea from a commentator, but I can't capture the text with 'Error' as that line occurs after the command completes...

Here's what it actually looks like, with incorrect password:

agent registration
username:
password:

Error login failed.

I tried this:

result=$(loginCmd | tee /dev/tty)

grep -q 'Error' <<< "$result" && 
    loginCmd

result doesn't capture the error string because the string outputs after the command completes:

result=agent registration

So I guess there is no way to capture this string?

Error login failed.

Any ideas?

Information from comments copied into the question so it can be more easily seen
Source Link
Chris Davies
  • 128.1k
  • 16
  • 179
  • 324
Loading
added 2 characters in body
Source Link
Nickotine
  • 554
  • 3
  • 17
Loading
Source Link
Nickotine
  • 554
  • 3
  • 17
Loading