0

Here is my connect.bat

-----BEGIN------

vpncmd localhost /client
accountconnect myConnectionName

-----END------

After executing connect.bat, here is the screen result:

Connected to VPN Client "localhost".

VPN Client>

accountconnect myConnectionName is not being executed.

How do I get accountconnect myConnectionName to run at the VPN Client> prompt?

Level1Coder
  • 245
  • 2
  • 10

2 Answers2

1

vpncmd can use a file with commands as an input, using the /IN:file switch.

This is the approach i would use to automate things.

Something like :

vpncmd localhost /client /in:commands.txt

Then put your command in commands.txt :

accountconnect myConnectionName

If you only want to send one command, then /IN switch could be an overkill.

In this case you could use the /CMD switch instead, something like :

vpncmd localhost /client /CMD accountconnect myConnectionName

Further reading about command line parameters :

krisFR
  • 13,280
  • 4
  • 36
  • 42
  • thanks! `/CMD` switch is working, one correction though, the double-quotes surrounding `"accountconnect myConnectionName"` is invalid. I had to remove them to have it run correctly. – Level1Coder Apr 05 '14 at 13:32
  • @Level1Coder ok great ! so feel free to mark it as "answered" ! sorry for the extras double-quotes : as i don't use this utility myself i just wrote it "blindly" ;) I have corrected my answer – krisFR Apr 05 '14 at 13:34
-4

This is a bash script written based on the following documentation https://www.softether.org/4-docs/1-manual/6._Command_Line_Management_Utility_Manual/6.2_General_Usage_of_vpncmd#6.2.3_Command_Line_Parameters_When_Starting_a_vpncmd_Command

#!/bin/bash
VPN_HOME=/usr/apps/vpnclient
NEW_IP=192.168.1.2
ACCOUNT_NAME=
function start(){

cd $VPN_HOME

sudo ./vpnclient start

./vpncmd localhost /client /CMD remoteenable
./vpncmd localhost /client /CMD accountconnect $ACCOUNT_NAME
#You can add your commands here

}

function stop(){
cd $VPN_HOME

sudo ./vpnclient stop
}
START="start"
STOP="stop"
HELP="help"

function help(){

 echo "#################################################################";      
 echo "#---------------------------Help--------------------------------#";      
 echo "#################################################################";     
 echo "./vpn-manger.sh command                                                  
 echo "-----------------------------------------------------------------";        
 echo "commands are $START , $STOP or $HELP"                                     
 echo "#################################################################";

}
function commands(){                                                              
       COMMAND=$1                                                                 
       case "${COMMAND,,}" in                                                     
                  "$START")       start;          ;;                                
                  "$STOP")        stop;           ;;                                
                  "$HELP")        help;           ;;                                       
                  *)              echo "Please Check your Command";    ;;                             
       esac                                                                            
}

commands $1;
Sven
  • 98,649
  • 14
  • 180
  • 226
Nuran
  • 101
  • 2
  • 1
    This question has already been answered with an accepted answer. Also, you included `!/bin/bash` in your script - this question was about Windows. In the future, when posting code/scripts, please format accordingly. – David Makogon Jun 22 '16 at 12:22