On Fri, 17 Apr 2020 08:05:28 +0000 Gregory Heytings <g...@sdf.org> wrote:

>
> Ranjan Maitra:
> >
> >> Wietse Venema:
> >>
> >> Corrected code follows (missing do/done).
> >>
> >> Save to file, chmod +x name-of-file, don't run this script from cron.
> >>
> >> It needs to be started at boot time, or before you make a VPN
> >> connection.
> >>
> >> #!/bin/sh
> >>
> >> while :
> >> do
> >>     ifconfig xxx | egrep 'UP|DOWN'
> >>     sleep 2
> >> done | while read status
> >> do
> >>     case "$status" in
> >>   *UP*) if [ "$prev" -ne up ]
> >>         then
> >>             prev=up
> >>             postconf -X defer_transports
> >>             postfix reload
> >>         fi;;
> >>      *) if [ "$prev" -ne down ]
> >>         then
> >>             prev=down
> >>             postconf defer_transports=smtp
> >>             postfix reload
> >>         fi;;
> >>     esac
> >> done
> >>
> >>         Wietse
> >>
> >
> > line 10: [: : integer expression expected
> >
> > Line10: is  the following line:
> >
> >  *UP*) if [ "$prev" -ne up ]
> >
>
> Wietse wrote earlier that this was "totally untested code".
>
> You should replace the two "-ne" with "!=".
>
> Also, $prev has not been assigned the first time the second loop ("while
> read status do ... done") is executed.  So you should add "prev=down"
> before the "while :".
>
> Finally, note that you should also replace the "xxx" (in "ifconfig xxx")
> with the actual name if your VPN interface, typically "tun0" or "tap0".
>

Yes, thanks very much for this. He did say untested code, but it has been very 
helpful!

Btw, for me, when ifconfig is DOWN, I do not get a down.

$  ifconfig xxx | egrep 'UP|DOWN'
xxx: error fetching interface information: Device not found

while:

$  ifconfig xxx | egrep 'UP|DOWN'
xxx: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1406

when it is up, with xxx being replaced by the name of the VPN tunnel.

I think I am going to modify the script to try:

$ nmcli connection show --active | grep xxx | echo $?

which is 0 or 1 depending on up or down.

Many thanks again for all the help from everyone, and best wishes,
Ranjan



--
Important Notice: This mailbox is ignored: e-mails are set to be deleted on 
receipt. Please respond to the mailing list if appropriate. For those needing 
to send personal or professional e-mail, please use appropriate addresses.

Reply via email to