Problems with korn shell script

Hey Guys,

I'm looking for some advice about a korn shell script I've written. I've spent hours googling for an answer hopefully someone here can help me out.

Basically the part of the script I'm having problems with is when I need to SFTP a file from one server to another. The line looks like this.

sftp -v $FTPUser@$FTPServer << EOF > $FTP_LOG

Heres the issue, the @ sign seems to be deleting the $FTPUser variable infront of it. I've placed an echo for the same line and it looks like this

echo $FTPUser@$FTPServer
@192.168.1.2

echo $FTPUser\@$FTPServer
\@92.168.1.2

The output is very odd. Does anyone know why the @ symbol is causing me such a headache?

printf "%s@%s" $FTPUser $FTPServer  | read username
sftp -v $username << EOF > $FTP_LOG
.....

Thanks for the fast reply Jim, however its still the same problem.

I setup an echo for username and it looks like this

echo $login

@172.23.21.25

I saw this forum question about the @ symbol before. @ symbol deleting all preceeding input at command line? - Unix Linux Forum

I've tried their fix but still no luck.

EDIT: Oh I forgot to mention, if I put the ftpuser and server like this ftp@serverip hard coded in the script it works fine.

I tried to reproduce the error at least 4 different ways, and I couldn't.

I just noticed that you set up an echo like:

 echo $login 

.. and you are also using $FTUser? How exactly are you passing this variable to that sftp command?

Thanks for helping out Jim.

Hers what I've been playing with, as you can see, I'm just desperately trying different things to get a different result. Oddly enough I've tried this on 3 different Solaris machines 5.7 5.9 and 5.10 all the with same result. Not sure if this is helpful, but I am running the script as root too.

printf "%s" $FTPServer | read login
echo $FTPUser
echo "$FTPUser"
NEWUSER = "$FTPUser"
echo "$login  $NEWUSER"
printf "%s@%s" $NEWUSER $FTPServer | read test
echo $test
echo "$NEWUSER $FTPUser $NEWUSER this Is weirdest problem I've ever had $login"

And heres the output.

shvftp
shvftp
2.23.21.25
@72.23.21.25
this Is weirdest problem I've ever had 172.23.21.25

I have no idea whats going on with it, I have a feelign ksh is to blame here, but I'm stuck using it as our heartbeat system requires me to use it. If I don't figure this out today I'm just going to hard code the values in and leave my predessor cursing my name when he has to maintain the script.

Heres something interesting, I reversed the FTPServer and FTPUser variables in the printf then echo'd test and it just looks like they are over writing each other...

My variables are defined in a seperate file and I know they are working properly. The second part of my script will ftp the file upon failure and that works fine. I'm sure it has something to do with the @ symbol, because everything works fine until I'm forced to use the username@server format

 
printf "%s" $FTPServer | read login
echo $FTPUser
echo "$FTPUser"
NEWUSER = "$FTPUser"
echo "$login  $NEWUSER"
printf "%s@%s" $FTPServer $FTPUser | read test
echo $test
echo "$NEWUSER $NEWUSER $NEWUSER this Is weirdest problem I've ever had $login"

shvftp
shvftp
2.23.21.25
@shvftp21.25
this Is weirdest problem I've ever had 172.23.21.25

No spaces around the =

NEWUSER = "$FTPUser"
NEWUSER="$FTPUser"