0

I wrote this script for an vpn connection. Now i want to check if the output which is stored in $vpn contains "Authentication failed". If it contains then it should exec. the script again.

There is no error, it just shows me nothing when i type the password not correct. The output of the vpn connection when i connect with a wrong password looks like this:

POST https://vpn.domain.de/
Verbunden mit XX.XX.XXX.XXX:443
SSL-Verhandlung mit vpn.domain.de
Verbunden mit HTTPS auf vpn.domain.de
Server forderte ein SSL Client-Zertifikat an. Es ist keines eingerichtet
POST https://vpn.domain.de/
XML POST aktiviert
POST https://vpn.domain.de/
Server forderte ein SSL Client-Zertifikat an. Es ist keines eingerichtet
POST https://vpn.domain.de/
XML POST aktiviert
POST https://vpn.domain.de/
**Authentication failed.**
Username:fgets (stdin): Die Ressource ist zur Zeit nicht verfügbar

Can somebody pls. tell me where my mistake is?

#!/bin/bash
echo Bitte Passwort eingeben:
read x
if [ -z "$x" ]
then
    echo "Kein Passwort eingegeben!!!"
        echo "Bitte erneut versuchen"
            exec "/home/ubuntu/Dokumente/vpn.sh"
else
        vpn=(echo $x |
        sudo openconnect vpn.domain.de --user=test.vpn --passwd-on-stdin --authgroup vpn-client-no-ise --no-dtls)
fi
if [[ $vpn == *"Authentication failed"* ]]; then
  echo "Dein Passwort war falsch!"
    exec "/home/ubuntu/Dokumente/vpn.sh"
fi
read
John Kugelman
  • 349,597
  • 67
  • 533
  • 578

1 Answers1

0

For saving output of some command in variable use backticks based syntax

example in your case:

vpn=`(echo $x |
        sudo openconnect vpn.domain.de --user=test.vpn --passwd-on-stdin --authgroup vpn-client-no-ise --no-dtls)`

or use $ for saving output

vpn=$(echo $x |
        sudo openconnect vpn.domain.de --user=test.vpn --passwd-on-stdin --authgroup vpn-client-no-ise --no-dtls)

reference: https://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output/

Vikas Mulaje
  • 727
  • 6
  • 11
  • sorry, i oversaw that. I now added the $ in front of the vpn=$( ). I now just says "Authentication failed" but it does not execute the script like i definned again – Uros Dobricic Apr 15 '20 at 15:17