Click to See Complete Forum and Search --> : .netrc files and cron jobs (RH7.1)


fracture
01-30-2002, 04:10 PM
I've got a RH7.1 (and a RH7.2) box that I'm trying to set up this mcafee uvscan auto-update script on. It relies on a .netrc file, which I've set up and placed in /root/.netrc. When I run the script from inside a root shell it runs perfectly, but when it runs nightly from the cron daemon it generates an error.

I really need this to work in a cron job so that the dats are updated daily. Any help is much appreciated.

The output from a normal, succesful command line execution, entering the command ./mcafee-dat-updates in the /etc/cron.daily directory gives the following output:


Current Version: 4171
Trying 64.41.192.109...
Connected to 64.41.192.109 (64.41.192.109).
220 ftp.nai.com FTP server
331 Anonymous login ok, send your complete email address as your password.
230 Anonymous access granted, restrictions apply.
cd pub/antivirus/datfiles/4.x
250 CWD command successful.
bin
200 Type set to I.
prompt
Interactive mode off.
mget dat-*.tar
local: dat-4183.tar remote: dat-4183.tar
227 Entering Passive Mode (64,41,192,109,250,32).
150 Opening BINARY mode data connection for dat-4183.tar (2283520 bytes).
226 Transfer complete.
2283520 bytes received in 14.8 secs (1.5e+02 Kbytes/sec)
close
221 Goodbye.
bye
New Version: 4183


When it bumps into an error during the cron job it gets this message, which looks to me like a missing .netrc

Current Version: 4183

Login failed.
Name (ftp.nai.com:root): New Version: *.ta
/usr/local/uvscan/updatedats: [: *.ta: integer expression expected
tar: dat-*.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: dat-*.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
/usr/local/uvscan/updatedats: [: *.ta: integer expression expected


There are three files involved,
1. The script at /usr/local/uvscan/updatedats
2. The cron job at /etc/cron.daily/mcafee-dat-updates
3. The .netrc file in /root/.netrc

I'll paste in the files at the end.

Here is the update script stored in
/usr/local/uvscan:

#!/bin/sh

# Assume uvscan is installed in the same directory
# as this script.
install_directory=`dirname $0`

# Create a download directory
mkdir /tmp/dat-updates
cd /tmp/dat-updates

# Get the version of the currently installed .DATs
# from the info given by the --version switch
current_version=`
$install_directory/uvscan --version |
grep "Virus data file" |
awk '{ print substr($4,2,4) }'`
echo Current Version: $current_version

# Get the new .DATs
# The entry in root's .netrc file should take care
# of the downloading
ftp ftp.nai.com

# Get the version of the new .DATs from the filename.
new_version=`echo dat-*.tar | awk '{ print substr($1,5,4) }'`
echo New Version: $new_version

# If they are the same age or older than the current ones,
# do not install them
if [ "$current_version" -ge "$new_version" ]
then
echo "No new .DATs available at this time"
echo "Currently installed version: $current_version"
echo "Version on FTP site: $new_version"
else
tar -xf dat-*.tar

# Move them ot the install directory, making sure
# the filename is lower case.
for file in `tar -tf dat-*.tar`
do
newfile=`echo $file | tr [A-Z] [a-z]`
mv ./$file "$install_directory/$newfile"
done

# Get the current version again and make sure
# the new .DATs installed correctly.
current_version=`
$install_directory/uvscan --version |
grep "Virus data file" |
awk '{ print substr($4,2,4) }'`

if [ ! "$current_version" -eq "$new_version" ]
then
echo "DAT file updates did not work correctly."
echo "Please try manually."
fi
fi
# Delete the directory that you created
cd /
rm -rf /tmp/dat-updates


Here is the cron job at /etc/cron.daily/mcafee-dat-updates. The --login on the first line was an effort to get it to find the .netrc file properly.

#!/bin/sh --login

/usr/local/uvscan/updatedats


And finally the .netrc file from /root/.netrc

machine ftp.nai.com
login anonymous
password root@test.com
macdef init
cd pub/antivirus/datfiles/4.x
bin
prompt
mget dat-*.tar
close
bye