Replace output of a command with a custom message

1

I am creating a script where at the end of it I execute a command that displays a very large output of information. Is it possible to replace this output? That is, instead of it showing the standard output show only one message eg Connected. ?

The command to run would be:

sudo openvpn --config srvproxy-udp-1194-config.ovpn

The output of it is thus typically:

  

Thu Sep 21 09:48:48 2017 WARNING: file 'srvproxy-udp-1194-tls.key' is   group or others accessible Thu Sep 21 09:48:48 2017 OpenVPN 2.4.0   x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11]   [MH / PKTINFO] [AEAD] built on Jun 22 2017 Thu Sep 21 09:48:48 2017   library versions: OpenSSL 1.0.2g 1 Mar 2016, LZO 2.08 Enter Auth   Username: xxxxxx Enter Auth Password: ******* Thu Sep 21 09:48:54 2017   TCP / UDP: Preserving recently used remote address:   [AF_INET] 200.210.150.105:1194 Thu Sep 21 09:48:54 2017 UDP local link   (bound): [AF_INET] [undef]: 0 Thu Sep 21 09:48:54 2017 UDP link remote:   [AF_INET] 200.210.150.105:1194 Thu Sep 21 09:48:54 2017 WARNING: this   configuration cache passwords in memory - use the auth-nocache   option to prevent this Thu Sep 21 09:48:54 2017 [www.xxxxxxx.com.br]   Peer Connection Initiated with [AF_INET] 200.210.150.105:1194 Thu Sep   21 09:48:55 2017 TUN / TAP device tun0 opened Thu Sep 21 09:48:55 2017   do_ifconfig, tt-> did_ifconfig_ipv6_setup = 0 Thu Sep 21 09:48:55 2017   / sbin / ip link set dev tun0 up mtu 1500 Thu Sep 21 09:48:55 2017   / sbin / ip addr add dev tun0 local 172.8.0.6 peer 172.8.0.5 Thu Sep 21   09:48:55 2017 Initialization Sequence Completed

    
asked by anonymous 21.09.2017 / 14:13

3 answers

2

You've tried:

sudo openvpn --config srvproxy-udp-1194-config.ovpn > /dev/null && echo "Conectado" || echo "Ops, tem algo errado"

?

    
21.09.2017 / 22:26
1

You can use an if in your script, discarding the output of the command:

#!/bin/bash

if openvpn --config srvproxy-udp-1194-config.ovpn >/dev/null 2>&1 ; then
        echo "Conectado"
else
        echo "Não conectado"
fi

If you need to save the output, you can redirect it to a log:
if openvpn --config srvproxy-udp-1194-config.ovpn > /tmp/openvpn.log ; then

    
21.09.2017 / 18:19
0

You can do it this way:

Let's use the ls command as an example

ls > saida.txt

It will throw all the output into the output file.txt and it will not show anything on the screen, you can parse the output in the output.txt file and then send the message to the user.

    
21.09.2017 / 14:41