Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Linux Shell ftp put script to HP-Ux ftp server fails when ftp to replacement Solaris ftp server

Posted on 2012-08-21
15
Medium Priority
?
2,113 Views
Last Modified: 2012-08-22
I have an ftp script which used to put text files over to
HP-Ux B11.11 ftp server.

A couple of days back, we replaced this HP-Ux with a Solaris
10 ftp server.  The Solaris server has a different IP addr
& we're supposed to decommission the HP-Ux server.

The only change to this Linux (Redhat 4.6 RHES) ksh script
is the IP addr of the remote ftp server.  Both the HP-Ux
& Solaris are on the same LAN as the Linux (just that the
Linux is in a different subnet).


If I manually ftp at command prompt from this Linux ftp
client to the Solaris server using the very same login id
& password (as the Shell script), it could login Ok, cd to
the destination directory & put a file successfully.

I suspected 3 lines are the possible culprits (indicated by ## below).

But if this script is run from Solaris cron it would fail with
incorrect login / password (see below for actual error messages).

If this script is run interactively on the Linux command line,
it was Ok but after running interactively a few times, it
doesn't allow me to login anymore.


any idea?

=========== Stdout & stderr outputs =============

GSSAPI error major: An invalid name was supplied
GSSAPI error minor: Cannot determine realm for numeric host address
GSSAPI error: parsing name
name parsed <ftp@172.16.25.58>

GSSAPI error major: An invalid name was supplied
GSSAPI error minor: Cannot determine realm for numeric host address
GSSAPI error: parsing name
name parsed <host@172.16.25.58>

GSSAPI authentication failed
KERBEROS_V4 rejected as an authentication type
Password:
ftp: bind: Address already in use
Login incorrect.
Login failed.
Passive mode refused.  Turning off passive mode.
GSSAPI error major: An invalid name was supplied
GSSAPI error minor: Cannot determine realm for numeric host address
GSSAPI error: parsing name
name parsed <ftp@172.16.25.58>

GSSAPI error major: An invalid name was supplied
GSSAPI error minor: Cannot determine realm for numeric host address
GSSAPI error: parsing name
name parsed <host@172.16.25.58>

======== Linux ftp script codes ==================

#!/usr/bin/ksh


JOB_DIR=$2
JOB_NAME=$3
FILE_LIST=$4
LOCAL_DIR=$5
REMOTE_DIR=$6

LOG_DIR=$JOB_DIR/log
ENV_SETTING="$JOB_DIR/cron_env.dat"


ERR_NAME=$JOB_NAME.err
LOG_NAME=$JOB_NAME.log
TMP_LOG_NAME=tmp_$JOB_NAME.log


IP=`grep Remote_IP $ENV_SETTING | cut -f2 -d =`
echo $IP >> /tmp/getmed.ip
FTP=`grep Remote_Login_id $ENV_SETTING | cut -f2 -d =`
echo $FTP >> /tmp/getmed.FTP
PASS=`grep Remote_Password $ENV_SETTING | cut -f2 -d =`
echo $PASS >> /tmp/getmed.PASS


for FILE_NAME in $FILE_LIST
do
if [ -r $LOCAL_DIR/$FILE_NAME ]
then
        if [ $1 == "append" ]
        then
                cat $LOCAL_DIR/$FILE_NAME >> $LOCAL_DIR/$FILE_NAME.append
                cp $LOCAL_DIR/$FILE_NAME.append $LOCAL_DIR/$FILE_NAME
        fi
fi
done

        ## echo "user $FTP"
        ## echo "\c"

        ## echo user
        ## echo "$FTP \c"


echo "--------------- Start Connecting to Remote Server at " `date` " ---------------">> $LOG_DIR/$LOG_NAME

       DATERUN=`date '+%Y%m%d%H%M'`
       {
        echo "open $IP"
        echo user              ## is this line the culprit or
        echo "$FTP \c"       ## this line or
        echo "$PASS"
        echo "verbose"
        echo "prompt off"
        echo "lcd $LOCAL_DIR"
        echo "cd $REMOTE_DIR"

        for FILE_NAME in $FILE_LIST
        do
        if [ -r $LOCAL_DIR/$FILE_NAME ]
        then
                        a1="tar"
                        a2=`echo $FILE_NAME | cut -f2 -d .`
                        if [ $a2 == $a1 ]
                        then
                                echo binary
                        else
                                echo binary
                        fi
                        echo "ren $FILE_NAME $FILE_NAME.bak"
                        echo "put $FILE_NAME"
                fi
        done

        echo bye

        } | ftp -n 2>&1 > $LOG_DIR/$TMP_LOG_NAME   ## this line??

        cat $LOG_DIR/$TMP_LOG_NAME >> $LOG_DIR/$LOG_NAME

        egrep "fail|refused|Not|error|incorrect|denied|unknown|timed out" $LOG_DIR/$TMP_LOG_NAME

        if [ "$?" -eq 0 ]; then
         sleep 3
      echo "--------------- Re-try to connect to Remote Svr ...,, at " `date` " ---------------" >> $LOG_DIR/$LOG_
NAME
         {
                echo "open $IP"
                echo user
                echo "$FTP \c"
                echo "$PASS"
                echo verbose
                echo "prompt off"
                #echo passive
                echo "lcd $LOCAL_DIR"
                echo "cd $REMOTE_DIR"

                for FILE_NAME in $FILE_LIST
                do
                if [ -r $LOCAL_DIR/$FILE_NAME ]
                then
                                a1="tar"
                                a2=`echo $FILE_NAME | cut -f2 -d .`
                                if [ $a2 == $a1 ]
                                then
                                        echo binary
                                else
                                        echo binary
                                fi
                                echo "ren $FILE_NAME $FILE_NAME.bak"
                                echo "put $FILE_NAME"
                        fi
                done

                echo bye
         } | ftp -n 2>&1 > $LOG_DIR/$TMP_LOG_NAME
         cat $LOG_DIR/$TMP_LOG_NAME >> $LOG_DIR/$LOG_NAME
        fi

       egrep "fail|refused|Not|error|incorrect|denied|unknown|timed out" $LOG_DIR/$TMP_LOG_NAME

        if [ "$?" -eq 0 ]; then
                #echo `date` "-----------$FILE_NAME :: Can't connect to Remote Svr: Connection refused, files are
kept at FTP Server"  >> $LOG_DIR/$ERR_NAME
                echo `date +%d_%B_%Y_%T` "-----------$FILE_NAME :: Can't connect to WEBLOGIC: Connection refused
, files are kept at FTP Server"  >> $LOG_DIR/$ERR_NAME
        else
                for FILE_NAME in $FILE_LIST
                do
                        if [ -r $LOCAL_DIR/$FILE_NAME ]
                        then
                            mv  $LOCAL_DIR/$FILE_NAME   $LOCAL_DIR/$FILE_NAME.$DATERUN
                            mv  $LOCAL_DIR/$FILE_NAME.md5   $LOCAL_DIR/$FILE_NAME.md5.$DATERUN
                        fi
                done
        fi

echo "--------------- End Connecting to Remote Server at " `date` " ---------------">> $LOG_DIR/$LOG_NAME

rm  $LOG_DIR/$TMP_LOG_NAME
0
Comment
Question by:sunhux
  • 7
  • 6
  • 2
15 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 1660 total points
ID: 38316293
Add IP and hostname to your DNS or to /etc/hosts.

If this doesn't already help use the remote hostname instead of the remote IP.
if  cron_env_dat contains just the IP, try to lookup the hostname with
HOST=$(host $IP)
Finally, in your script replace $IP with $HOST.
0
 

Author Comment

by:sunhux
ID: 38316385
No joy
0
 

Author Comment

by:sunhux
ID: 38316414
Still getting the same invalid login messages
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 1660 total points
ID: 38316458
Well,

maybe "echo" on the new server doesn't recognize "\c" (ksh's echo should, however).
Anyway, you could try

echo "$FTP $PASS"

in one line.
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 1660 total points
ID: 38316611
... or do you indeed use Kerberos?

In this case it seems that you didn't add the new machine to the Kerberos realm.
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 340 total points
ID: 38316640
Have you done any changes on the system recently?

Can you run the script with logging and see which step causes the error? you can run it with

ksh -x scriptname
0
 

Author Comment

by:sunhux
ID: 38316728
>didn't add the new machine to the Kerberos realm.
On the Solaris end, "svcs -a | grep krb" showed Kerberos is
disabled.  Also, ftp at command prompt works.

ksh -v scriptname   or   sh -v scriptname
with  > file1.txt   and   2> file2.txt   gave
nothing in file2.txt but the following in file1.txt:
(as given in my first post above):

If I manually ftp at command prompt from this Linux ftp
client to the Solaris server using the very same login id
& password (as the Shell script), it could login Ok, cd to
the destination directory & put a file successfully.




=========== Stdout & stderr outputs =============

GSSAPI error major: An invalid name was supplied
GSSAPI error minor: Cannot determine realm for numeric host address
GSSAPI error: parsing name
name parsed <ftp@172.16.25.58>

GSSAPI error major: An invalid name was supplied
GSSAPI error minor: Cannot determine realm for numeric host address
GSSAPI error: parsing name
name parsed <host@172.16.25.58>

GSSAPI authentication failed
KERBEROS_V4 rejected as an authentication type
Password:
ftp: bind: Address already in use
Login incorrect.
Login failed.
Passive mode refused.  Turning off passive mode.
GSSAPI error major: An invalid name was supplied
GSSAPI error minor: Cannot determine realm for numeric host address
GSSAPI error: parsing name
name parsed <ftp@172.16.25.58>

GSSAPI error major: An invalid name was supplied
GSSAPI error minor: Cannot determine realm for numeric host address
GSSAPI error: parsing name
name parsed <host@172.16.25.58>
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38316760
Did you read my #38316458 above?
0
 

Author Comment

by:sunhux
ID: 38316768
The following works:

.....  open $IP .....
echo "quote USER $USER"
echo "quote PASS $PASS"
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 38316836
did you read my comment ID: 38316640
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 1660 total points
ID: 38317263
The main reason why it works seems to be that you're avoiding "\c" after "echo" and not that you're using "quote".

See my comment.
0
 

Author Comment

by:sunhux
ID: 38320448
Yes, I saw both your comments

but the following probably has typo error as we can't echo username
& password on the same line, syntax not supported:
 > echo "$FTP $PASS"

while,
I've indicated that the backend/remote servers were migrated
from HP-Ux to Solaris, no other changes.  I've also done "ksh -v"
but it only points to the fact that there's invalid login id/password:

 > Have you done any changes on the system recently?
 > Can you run the script with logging and see which step causes
 > the error? you can run it with "ksh -v scriptname"

Or do you mean "ksh -x"  (I always thought it's -v )
0
 

Author Comment

by:sunhux
ID: 38320456
Even if I remove "\c" in the original scripts, it doesn't work too.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1660 total points
ID: 38320469
echo "user $FTP $PASS"

of course. Sorry.
0
 

Author Comment

by:sunhux
ID: 38320611
No problem with the typo.

Both of you have helped me a lot in EE.
Closing this thread as my 'enormous' problem
is now resolved.

The fact that both of you responded promptly in itself
is a morale support to me.  Certain management at
my place can be very demoralizing
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question