Re: [Fish-users] How to use functions with --on-signal properly?
Status: Beta
Brought to you by:
liljencrantz
|
From: Glenn J. <ja...@py...> - 2020-07-24 01:10:26
|
On Thu, Jul 23, 2020 at 3:58 PM Tassilo Horn <ts...@gn...> wrote:
> My actual use-case is a script that will eventually call openconnect to
> establish a VPN connection to my work network. During my work day, I'll
> mount several samba shares from that network and usually I forget to
> umount them before C-c-ing the script. Then the system shutdown will
> hang because the system tries to umount them which won't work without
> VPN connection. So I want some mechanism to umount those shares
> _before_ the VPN connection is closed.
>
This is a good use case for Expect, I think. Something like
```tcl
#!/usr/bin/env expect
spawn openvpn ...
expect Password
send -- "$password\r"
# any other prompts before the connection is made...
interact {
\x003 {
# user hit Ctrl+C
foreach mount {/mnt/a /mnt/b /mnt/c} {
puts "unmounting $mount"
exec umount $mount
}
send \x003 ;# send the Ctrl+C to openvpn
}
}
puts "bye"
```
--
*Glenn Jackman*
Senior Software Developer
*Pythian - Love your data*
ja...@py...
Tel: +1 613 565 8696 Ext. 1478
Mobile: +1 613 808 4984
www.pythian.com
--
--
|