LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-01-2004, 09:27 AM   #1
pk_fox
Member
 
Registered: Oct 2003
Location: London, UK
Distribution: Fedora Core 2
Posts: 41

Rep: Reputation: 15
Help with shell script


Hello all, I have a problem with a script which came as part of a book example, the first line of the script after the #!/bin/sh line is simply this: SSH_DIR=/opt/ssh-dir, the directory exists and is readable by everyone, however when I run the script I receive this error: "SSH_DIR is a directory" the script then terminates, any ideas what this might be ??

regards

Pete Kane
 
Old 09-01-2004, 09:32 AM   #2
bruno buys
Senior Member
 
Registered: Sep 2003
Location: Rio
Distribution: Debian
Posts: 1,513

Rep: Reputation: 46
I'm not sure about it, but if you want to set it as an env. variable, you must do
export SSH_DIR=/opt/ssh-dir
instead.
 
Old 09-02-2004, 04:19 AM   #3
pk_fox
Member
 
Registered: Oct 2003
Location: London, UK
Distribution: Fedora Core 2
Posts: 41

Original Poster
Rep: Reputation: 15
sorry the error message is: "/opt/ssh-dir is a directory", if I run the script as root the error message is: "/root is a directory"

regards

Pete Kane
 
Old 09-02-2004, 09:26 AM   #4
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Hi,

Can you post more of your script? cause, it's probably when the script uses "$SSH_DIR" variable that the script fails.

Oliv'
 
Old 09-03-2004, 04:42 AM   #5
pk_fox
Member
 
Registered: Oct 2003
Location: London, UK
Distribution: Fedora Core 2
Posts: 41

Original Poster
Rep: Reputation: 15
here it is in its entirety, thanks for your time


#!/bin/sh

# Change me to the appropriate location of
# your SSH VPN installation directory
SSH_VPN_DIR=/opt/ssh-vpn


# No changes should be necessary from here down.


vpn_config () {
vpn_network=$1

# Grab global variables
. $SSH_VPN_DIR/etc/ssh-vpn.conf || exit 0

# Grab vpn-specific variables
VPN_CONFIG=$SSH_VPN_DIR/etc/$vpn_network
. $VPN_CONFIG || exit 0

if [ "$client_debug" = "yes" ] ; then
set -x
client_pppd_args="$client_pppd_args debug"
fi
}

run_as_sshvpn () {
whoami=`$WHOAMI`
pwd=`pwd`
case "$whoami" in
root) exec $SU - $SSH_VPN_USER "-ccd $pwd;$0 $*";
exit 0; ;;
$SSH_VPN_USER) ;;
*) echo "$0 Must be run as $SSH_VPN_USER" >&2;
exit 1; ;;
esac
}

# Determine how we should behave:

if [ ! -z "$LINKNAME" ] ; then
# We were called as the ip-up script from pppd

vpn_config $LINKNAME

# Configure our new route
# sudo not needed -- we were run from pppd as root

# $IPREMOTE is set by pppd for us
[ "$server_network" ] && $ROUTE add -net $server_network gw $IPREMOTE

exit 0;

elif [ "$1" = "stop" ] ; then
# We were invoked init.d style, as one of the following:
# /etc/init.d/vpn-client stop vpn1
# /etc/init.d/vpn1 stop
# /etc/rcX.d/S##vpnname stop

[ "$2" ] && vpn_config "$2" \
|| vpn_config `basename $0 | sed -e 's/^[SK][0-9][0-9]//'`

# Kill off the pppd and stunnel processes
kill `head -1 $PIDDIR/ppp-$vpn_network.pid` 2>/dev/null
exit 0;

elif [ "$1" = "start" ] ; then
# started init.d style, similar to above.

[ "$2" ] && vpn_config "$2" \
|| vpn_config `basename $0 | sed -e 's/^[SK][0-9][0-9]//'`

run_as_sshvpn "$@" # Make sure we're not root, etc.

# Fall through to actual startup stuff.

elif [ $# -eq 1 ] ; then
vpn_config $1
run_as_sshvpn "$@" # Make sure we're not root, etc.

# Fall through to actual startup stuff.

else
echo "Usage: $0 destination start|stop" >&2
echo "Usage: $0 start|stop" >&2
echo "Usage: (if $0 is a vpn name)" >&2
exit 1
fi


# Universal ssh arguments
# (yes, that's two '-t' entries here)
SSH_ARGS="-oBatchMode=yes -enone -t -t"

# Universal pppd arguments
PPPD_ARGS="updetach lock connect-delay 10000 name $vpn_network-client \
user $vpn_network-client linkname $vpn_network \
remotename $vpn_network-server $client_pppd_args pty"

# Munge PPPD_ARGS for desired auth level
if [ "$client_require_pap" = "yes" ] ; then
PPPD_ARGS="require-pap $PPPD_ARGS"
elif [ "$client_require_chap" = "yes" ] ; then
PPPD_ARGS="require-chap $PPPD_ARGS"
else
PPPD_ARGS="noauth $PPPD_ARGS"
fi


# Start our pppd/ssh processes
$SUDO $PPPD $PPPD_ARGS \
"$SUDO -u $SSH_VPN_USER $SSH $SSH_ARGS $client_ssh_args $vpn_network"
 
Old 09-03-2004, 04:49 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, there's no SSH_DIR var in that script.... why don't you try
set -xv
as the first line, which will show you exactly what it's doing.
 
Old 09-03-2004, 07:10 AM   #7
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Quote:
root) exec $SU - $SSH_VPN_USER "-ccd $pwd;$0 $*";

I think the error comes from this line. Try to insert before and after a line like: echo "before error" and echo "after error" to know if I'm right If I'm right, we need to know more about ccd option to debug it

Oliv'
 
Old 09-06-2004, 04:17 AM   #8
pk_fox
Member
 
Registered: Oct 2003
Location: London, UK
Distribution: Fedora Core 2
Posts: 41

Original Poster
Rep: Reputation: 15
thanks to you both I'll give it a try when I'm back at my desk

regards

Pete Kane
 
Old 09-08-2004, 06:12 AM   #9
pk_fox
Member
 
Registered: Oct 2003
Location: London, UK
Distribution: Fedora Core 2
Posts: 41

Original Poster
Rep: Reputation: 15
Hello all, sorry for the delay in posting ( damn work !) the problem turned out to be blank lines at the end of the conf file, which is read on this line

# Grab global variables
. $SSH_VPN_DIR/etc/ssh-vpn.conf || exit 0

I have another problem now which is ppp authentication, but that's another story

regard and thanks for all your help

Pete Kane
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 03:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration