Hi all,
I use the open source vpn client, named vpngate -- see here for detail
http://www.vpngate.net/ -- to access some websites under my Debian Wheezy
box.
This softerware has a command line management utility, i.e., vpncmd
command. Which let the users, especially the ones under *nix os's to do
the management jobs with the shell scripts.
The following is a simple script which do some setting jobs for the
client side -- I've give some comments on each line of these commands:
--------------
# Start the vpngate client service, so that the vpncmd
# can connect to it for doing some management jobs:
sudo vpnclient start
# Connect to vpngate client service running on the localhost,
# and create a virtual network adapter named nic:
sudo vpncmd /client localhost /CMD niccreate nic
# Delete the virtual network adapter named nic:
sudo vpncmd /client localhost /CMD nicdelete nic
# Stop the vpngate client service:
sudo vpnclient stop
--------------
The issue is, when I running the above commands from a script, I'll meet
the errors as follows -- I've used the script file test-vpngate.sh which
includes the above commands:
---------------
werner@debian:~$ bash test-vpngate.sh
The SoftEther VPN Client service has been started.
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.14 Build 9529 (English)
Compiled 2015/02/02 17:33:33 by yagi at pc30
Copyright (c) SoftEther VPN Project. All Rights Reserved.
Error occurred. (Error code: 1)
Connection to the server failed. Check network connection and make sure
that address and port number of destination server are correct.
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.14 Build 9529 (English)
Compiled 2015/02/02 17:33:33 by yagi at pc30
Copyright (c) SoftEther VPN Project. All Rights Reserved.
Connected to VPN Client "localhost".
VPN Client>nicdelete nic
NicDelete command - Delete Virtual Network Adapter
Error occurred. (Error code: 29)
Object not found.
Stopping the SoftEther VPN Client service ...
SoftEther VPN Client service has been stopped.
---------------
It seems that the issues are caused by the vpngate client service
relative the first command -- this command require some times for
starting, and the following commands cann't use this service for doing
jobs. So I change the script into the following form:
---------------
sudo vpnclient start
sleep 1
sudo vpncmd /client localhost /CMD niccreate nic
sudo vpncmd /client localhost /CMD nicdelete nic
sudo vpnclient stop
---------------
And at this point, all of the commands will executed successfully:
--------------
werner@debian:~$ bash test-vpngate.sh
The SoftEther VPN Client service has been started.
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.14 Build 9529 (English)
Compiled 2015/02/02 17:33:33 by yagi at pc30
Copyright (c) SoftEther VPN Project. All Rights Reserved.
Connected to VPN Client "localhost".
VPN Client>niccreate nic
NicCreate command - Create New Virtual Network Adapter
The command completed successfully.
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.14 Build 9529 (English)
Compiled 2015/02/02 17:33:33 by yagi at pc30
Copyright (c) SoftEther VPN Project. All Rights Reserved.
Connected to VPN Client "localhost".
VPN Client>nicdelete nic
NicDelete command - Delete Virtual Network Adapter
The command completed successfully.
Stopping the SoftEther VPN Client service ...
SoftEther VPN Client service has been stopped.
---------------
Now, I change the script into the following form:
------------
sudo vpnclient start
wait
sudo vpncmd /client localhost /CMD niccreate nic
sudo vpncmd /client localhost /CMD nicdelete nic
sudo vpnclient stop
------------
And again, the script will failed to execute as follows:
------------
werner@debian:~$ bash test-vpngate.sh
The SoftEther VPN Client service has been started.
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.14 Build 9529 (English)
Compiled 2015/02/02 17:33:33 by yagi at pc30
Copyright (c) SoftEther VPN Project. All Rights Reserved.
Error occurred. (Error code: 1)
Connection to the server failed. Check network connection and make sure
that address and port number of destination server are correct.
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.14 Build 9529 (English)
Compiled 2015/02/02 17:33:33 by yagi at pc30
Copyright (c) SoftEther VPN Project. All Rights Reserved.
Connected to VPN Client "localhost".
VPN Client>nicdelete nic
NicDelete command - Delete Virtual Network Adapter
Error occurred. (Error code: 29)
Object not found.
Stopping the SoftEther VPN Client service ...
SoftEther VPN Client service has been stopped.
------------
So my issues are as follows:
1- Why sleep can let the script executed successfully, while the wait
cann't do the trick?
2- If I want to use a more precising time for sleeping, say, to execute
all of the subsequent commands immediately the vpngate client service
been started. How should I revise my commands? And is this possible?
Regards
--
.: Hongyi Zhao [ hongyi.zhao AT
gmail.com ] Free as in Freedom :.