Problems with korn shell script


 
Thread Tools Search this Thread
Operating Systems Solaris Problems with korn shell script
# 1  
Old 10-09-2008
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?
# 2  
Old 10-09-2008
Code:
printf "%s@%s" $FTPUser $FTPServer  | read username
sftp -v $username << EOF > $FTP_LOG
.....

# 3  
Old 10-09-2008
Thanks for the fast reply Jim, however its still the same problem.

I setup an echo for username and it looks like this

Code:
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.

Last edited by hilather; 10-09-2008 at 04:40 PM..
# 4  
Old 10-09-2008
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:
Code:
 echo $login

.. and you are also using $FTUser? How exactly are you passing this variable to that sftp command?
# 5  
Old 10-09-2008
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.

Code:
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.
# 6  
Old 10-09-2008
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

Code:
 
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
# 7  
Old 10-10-2008
No spaces around the =
Code:
NEWUSER = "$FTPUser"
NEWUSER="$FTPUser"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Korn Shell Loop Problems

Very new to the Korn Shell, but I've been looking up loops online and it seems this should work. I'm just trying to convert an ip range in variables $A and $B and iterate the individual ip's out to new lines. Unfortunately I get {152..155} instead of 152, 153, 154, and 155. # for i in {$A..$B};... (8 Replies)
Discussion started by: Azrael
8 Replies

2. Shell Programming and Scripting

pass null value to sql script from korn shell script

There are 4 parameters that I have to pass from korn shell to sql script. 1) I have to check if $1 , $2 , $3 and $4 are null values or not . How can I do that ? 2) Once its determined that these values are null (in the sense they are empty) how can I pass null values to sql script... (11 Replies)
Discussion started by: megha2525
11 Replies

3. Shell Programming and Scripting

running a script in korn shell

I'm learning bash and have discovered that the shell can only work with integers and not decimals. I'd like to run my scripts in korn to account for this, but just now, when I tried to run my script, I got an error message that said 'no such file or directory,' even though when I'm in the shell... (3 Replies)
Discussion started by: Straitsfan
3 Replies

4. AIX

weird korn shell script

here is the one of the scripts: script1.kshfunction haha { print "calling haha" exit } script2.ksh. script1.ksh haha | tee -a /dev/null print "i am script 2" after launching the script2, the result: --------------------------------------------- calling haha i am script 2 ... (6 Replies)
Discussion started by: getter
6 Replies

5. Homework & Coursework Questions

Korn Shell Script

1. The problem statement, all variables and given/known data: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. 2. Relevant commands, code,... (3 Replies)
Discussion started by: burm
3 Replies

6. Shell Programming and Scripting

Korn Shell Script

I have to solve some exercises in Korn Shell, but i'm having some problems. For example: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. I... (3 Replies)
Discussion started by: burm
3 Replies

7. AIX

Help with Korn Shell script

I have this Korn shell script that runs via a cron entry. It runs in a loop "watching" a specific file system for files with a certain name. The file system that it is watching is an upload file system for an FTP server. When files that are the correct name come in, it takes the extension of the... (1 Reply)
Discussion started by: heprox
1 Replies

8. UNIX Desktop Questions & Answers

korn shell script

hi all i am writing the korn shell script. i have a SQL script which gives me the folowing output DSA.WLG.20050713211544.20051025.20050713211544 28991 1130198400 DSA.WLG.20050713211544.20051025.20050713211544 25881 1130198400 DSA.WLG.20050711210100.20051025.20050711210100 25881 ... (3 Replies)
Discussion started by: pavan_test
3 Replies

9. UNIX for Dummies Questions & Answers

korn shell script

hello., i have 2 files.. 1 file is in this folder /home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544 (this part) other file is in this folder /home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100 ... (1 Reply)
Discussion started by: pavan_test
1 Replies

10. UNIX for Dummies Questions & Answers

su and password in a Korn shell script

Hi All, In my shell script I want to use su - userid and provide password for this user, but I don't know the syntax to do this, can anyone tell me what it is? I have tried: su - userid/password and su - userid password but no luck... (2 Replies)
Discussion started by: Melissa
2 Replies
Login or Register to Ask a Question