Starting Shrewsoft from a bash script

Viewed 655

Summary

Connecting to Shrew soft vpn
- terminal -- command works fine
- bash script -- same command returns error:

"double free or corruption (out)"

Problem

I often connect to my work vpn using the shrewsoft vpn client. I'd like to create a bash script so that I can use a single command to set up the vpn client, as well as a few other environment variables. When I run the command from the terminal, it works fine. But the same command in a bash scrip fails.

Terminal Command

ikec -r "<shrewsoft vpn connection name>" -u "john" -p "<password>" -a

Bash Script

#! bash
ikec -r "<shrewsoft vpn connection name>" -u "john" -p "<password>" -a

and then in the terminal I'm running the command:

> sudo bash ./vpn_connection.sh

I've already started "sudo /usr/sbin/iked". From the terminal, I can connect and disconnect successfully running that command, but when I run it from the bash script, I get an error.

1 Answers

When your shell script runs, it loses any environment variables you defined but did not export. When you run your script under sudo, sudo clears the environment except for a few variables.

It might be that that ikec relies on a missing environment variable, or perhaps that the ikec that's executed by the script isn't the same one, perhaps because of a PATH change, or alias.

I wouldn't use a script for this, by the way. I would use an alias or a function. In your ~/.profile or ~/.bash_profile (whichever you use) try:

alias vpn-connect='ikec -r "<shrewsoft vpn connection name>" \
      -u "john" -p "<password>" -a'

Then you can connect simply with

$ vpn-connect

However, the point made in the comments about passwords in files is well taken. Look for a way to connect to your vpn without providing a password. If you can't, you might just leave that option out of the alias, and let ikec prompt you for it.

Related