Steps to automate the ftp process using a shell script and .netrc in a Lawson token

 0 Replies
 0 Subscribed to this topic
 68 Subscribed to this forum
Sort:
Author
Messages
Tony
New Member Send Private Message
Posts: 0
New Member

·         Setup the IP addresses in the hosts file in /etc directory, this make it cleaner.

 

Sample:

123.456.7.8       CMPX     ## Company X

Where the alias to use in the script is going to be CMPX

Once this entry is done in the hosts file go to the home directory of the user if is different than Lawson.

At the user’s home directory create a .netrc file. This file will contain the following information:

 

machine CMPX login userid password psswd1                            

macdef init

prompt

lcd /lawson/law/prod/work/testfile/              

cd /target_dir/vendor_dir

mget test*.csv                                                              

mdelete test*.csv

quit

 

Make sure there is an empty line after the last command (quit)

Change the ownership to the user and change the privileges to 600 to the .netrc

This process will login into the target server CMPX (123.456.7.8)

And will get all the files (wildcard) with the beginning name test and the extension csv.

This command is to get multiple files in the specified directory, and after the files are obtained then delete the files from that server (CMPX), if needed.

 

commands to remember:

 

mget – Multiple get

mdelete – multiple delete

mput – multiple put

get – single file get and the name needs to be specified

delete – single file delete and the name needs to be specified

put – single file put and the name has to be specified.

 

 

·         After this part is done then you are ready to create the shell script to run this process.

 Script sample:

############################################################################

#!/usr/bin/ksh                                                                                                                                            #     

#Name: script_sample.sh                                                                                                                         #

############################################################################

# Export Global Variables

export MAILRECIP=peoples@sample.com

 

# Check if log file exist to log all the activity during this process.

# Create a clean log file to log the activity

 

if test ! -s $FILELOC/TRANSFER.log

   then

   echo "log file does not exist - Create one "

   date > $FILELOC/TRANSFER.log

else

  rm   $FILELOC/TRANSFER.log

  date >  $FILELOC/TRANSFER.log

fi

###  FTP File to Target server

if test ! -s $FILELOC/$FILENM1$DATE$FILENM2".pgp"

   then

            echo "There is not file to transmit " >>  $FILELOC/TRANSFER.log

    else

                echo " Here the FTP start  " >>  $FILELOC/TRANSFER.log

 

               ftp -v CMPX >>  $FILELOC/TRANSFER.log

fi

echo " Getting or transmitting  File(s) Transmission  " >>  $FILELOC/TRANSFER.log

##  Send email to someone with the log on the body of the email. You can use as many recipients

##  Subject line is FTP Status.

 

mail -s "FTP Status"  $MAILRECIP  < $FILELOC/TRANSFER.log

 

 

 

·         Last step is to create a token for the script and create a job to run the script automatically.