10.12 Creating an IP Alias

10.13 The .netrc File

The $HOME/.netrc file contains information used by the automatic login feature of the rexec and ftp commands. It is a hidden file in a user's home directory and must be owned either by the user executing the command or by the root user. If the .netrc file contains a login password, the file's permissions must be set to 600 (read and write by owner only).

Note

The .netrc file is not used by any programs when the securetcpip command is running on your system.

The ftp command interpreter provides facilities to load macros from the $HOME/.netrc file. With the .netrc file, you can simplify repetitive tasks and use the ftp command in unattended modes.

Note

The maximum size of the .netrc file is 4096 bytes. If you need to use more than 4096 bytes, you have to split up your file into multiple parts and write a script to automate the FTP job.

10.13.1 The .netrc File Format

The .netrc file can contain the following entries (separated by spaces, tabs, or new lines):

machine HostName
The HostName variable is the name of a remote host. This entry begins the definition of the automatic login process for the specified host. All following entries up to the next machine entry or the end of the file apply to that host.
login UserName
The UserName variable is the full domain user name for use at the remote host. If this entry is found, the automatic login process initiates a login using the specified name. If this entry is missing, the automatic login process is unsuccessful.
password Password
The Password variable is the login password to be used. The automatic login process supplies this password to the remote server. A login password must be established at the remote host, and that password must be entered in the .netrc file. Otherwise, the automatic login process is unsuccessful, and the user is prompted for the login password.
account Password
The Password variable is the account password to be used. If this entry is found, and an account password is required at the remote host, the automatic login process supplies the password to the remote server. If the remote host requires an account password, but this entry is missing, the automatic login process prompts for the account password.
macdef MacroName
The MacroName variable is the name of an FTP subcommand macro. The macro is defined to contain all of the following FTP subcommands up to the next blank line or the end of the file. If the macro is named in it, the ftp command executes the macro upon successful completion of the automatic login process. The rexec command does not recognize a macdef entry.

10.13.2 Sample .netrc File

A sample .netrc file is created by modifying one of the files created by the fixdist package. Only one of the fixes to be downloaded is retained for illustration purposes. In essence, Figure 98 shows the content of a typical .netrc file.



Figure 98: A Sample .netrc File

If you are using your own user name and password, replace anonymous with your own user name and pw0rd with your password.

10.13.3 Handling Multiple .netrc Files

You can use a simple script to handle multiple .netrc files to use the ftp command in unattended mode. When you are downloading a large number of fixes, do this after office hours in unattended mode. The fixdist package will create multiple .netrc files with suffixes 1, 2, 3, and so on such that each file is smaller than 4096 bytes. The sample script as shown in Figure 99 will copy each .netrc file with suffixes 1, 2, 3, and so on to the $HOME directory and then execute the ftp command.


#!/usr/bin/ksh
for i in .fixdist_home/.netrc[0-9]*  # .netrc0 1 2...10 11 12...
do
 cp $i .netrc                        # ftp script to be used
 ftp -v service.software.ibm.com >> ./ptfload.log 2>&1
                                     # Download fixes and save output
done
rm .netrc                            # Clean up ftp script
Figure 99: A Sample Script to Download Fixes

Note

Additional coding should be added to verify whether the download of individual fixes has been successful and include a housekeeping routine, if needed. But that is outside the scope of FTP and the .netrc file.

Submit the job using the at command so that the script will be executed at the time you have planned. For example, if you have a script called getfixes and you want to schedule it to run at 11 p.m. on 2 November 1998, you will use:

at -f getfixes -t 199811022300

10.14 The uname Command