Toon posts:

[Debian] 'programmeren' in ftp

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hallo iedereen,

Ik ben bezig met het schrijven van een auto-update script voor m'n McAfee dat-files (linux scanner). Het standaard-script beviel me niet zo, omdat ie dan altijd eerst het bestand gaat downloaden, en daarna pas gaat controleren of het wel een nieuwere versie is. Wat ik dus nu wil doen, is gewoon door middel van het controleren van de bestandsnaam, kijken of het een nieuwere versie is. Dus ik doe:
code:
1
2
prompt off
ls dat-*.tar

En nu wil ik dat laatste commando in een variabele kwijt. dus een soort van:
code:
1
2
prompt off
$test = `ls dat-*.tar`

En daarna de connectie beindigen, om de variabele te controleren (de variabele MOET dus ook buiten ftp om nog blijven bestaan!
Als dan de file nieuwer blijkt te zijn, dan gaan we die maar eens downloaden, en anders: einde oefening, exit 1.

Iemand enig idee hoe ik dit voor elkaar ga krijgen? Een ander ftp proggie dan het standaard 'ftp' mag ook hoor! Als het maar automatisch gaat!

  • MyDyingBride
  • Registratie: November 2001
  • Laatst online: 28-07 20:19
Zoiets heb ik ook eens gemaakt.
Je kan een 'ls dat*.zip /tmp/blabla' doen.
In /tmp/blabla komt dan het resultaat van het ls commando te staan.

Als je wilt kan ik het scriptje wel ff naar je mailen ofzo.

Verwijderd

Topicstarter
is goed! b_cyberguy@yahoo.com

  • MyDyingBride
  • Registratie: November 2001
  • Laatst online: 28-07 20:19
Hij is onderweg.

Je kan ook eens naar ncftpls kijken, onderdeel van het ncftp pakket.

  • Shir
  • Registratie: November 2000
  • Laatst online: 25-11-2025
'k weet niet van wie deze is (gebruiken we op het werk), maar het werkt goed (zie ook http://www.amavis.org/contrib/ :
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Changelog
# 5 apr 2001  - try to find the location of the scan software automatically
#        - make the user to warn a variable (WARN)
#        - add comments
# 4 apr 2001  - added -F to ncftpls
#        - introduction of function fetchfile
# 30 nov 2001 - removed -F (passive mode)


# Where do we log the datfiles we've received
LOGDIR=/var/log/mcafee

# McAfee's ftp server + the path to the datfiles (without leading /)
FTPSERVER=ftpeur.nai.com
#FTPSERVER=ftp.nai.com
FTPDIR=pub/datfiles/english

# Directory for temporary files
TMP=/tmp/uvscanupdate.$$

# Location of then antivirus software and datfiles. First try to find
# it automatically by looking for a unique clean.dat. If not found, try
# the default installation dir
if [ `locate clean.dat 2> /dev/null | wc -l` -eq 1 ] ; then
      UVDIR=`dirname \`locate clean.dat\``
      [ ! -x $UVDIR/uvscan ] && unset UVDIR
fi
[ ! $UVDIR ] && UVDIR=/usr/local/uvscan

if [ ! -f $UVDIR/clean.dat ] ; then
      echo "Could not find the location of the software"
      exit
fi

# The password to use for anonymous login
PASSWD="anonymous@noplace.com"

# User to warn in case of errors
WARN=root

# This function does the actual work: it gets the datfiles and
# puts them in the $TMP directory. $1 is the filename to get.
function fetchfile () {
      ncftpget -d $TMP/ERRS -r 3 -t 120 -v -p $PASSWD \
        $FTPSERVER $TMP /$FTPDIR/$1 > /dev/null 2>&1
      echo $?
}

# Find out what the latest datfile is and if there's an extra.dat
for i in `ncftpls -1 -p $PASSWD ftp://$FTPSERVER/$FTPDIR/ 2>/dev/null \
        | grep -i -e ^dat\-4.*\.tar$ -e ^extra\.dat$` ; do
      if [ $i = "extra.dat" ] ; then
            EXTRA=yes
      else
            LATEST=$i
      fi
done

# Huh? No datfiles: print error message
if [ "$LATEST" = "" -a "$EXTRA" = "" ] ; then
      echo "No datfiles found. Communication error?"
      exit
fi

if [ -f $LOGDIR/$LATEST ] ; then
      echo "Current datfile ($LATEST) is up to date. No need to download."
else
      # There's a new datfile. Fetch it!

      mkdir $TMP

      ERR=`fetchfile $LATEST`

      if [ $ERR -eq 0 ] ; then
            # No errors: untar the datfile

            tar xf $TMP/$LATEST -C $UVDIR

            # No errors: touch logfile and show version by running
            # uvscan --version
            if [ $? -eq 0 ] ; then

                [ ! -d $LOGDIR ] && mkdir $LOGDIR
                touch $LOGDIR/$LATEST
                echo -e "Datfile updated to $LATEST\n"
                $UVDIR/uvscan --version
            fi
      else
            # Errors during fetch: Mail sysop
            (echo -e "Ncftpget terminated with status $ERR\n"
         cat $TMP/ERRS) | mail -s "Errors during uvscan-update" $WARN
      fi
fi

# If there's an extra.dat, fetch it.
if [ "$EXTRA" = "yes" ] ; then

      [ `fetchfile extra.dat` -eq 0 ] && mv -f $TMP/extra.dat $UVDIR
fi

# Clean up
rm -fr $TMP

  • deadinspace
  • Registratie: Juni 2001
  • Laatst online: 16-08 16:08

deadinspace

The what goes where now?

Een voorbeeldje van hoe je dit aan kan pakken (ik weet niet of ftp ipv lftp vervelend doet met die '*' in de filename, magoed):
code:
1
2
3
4
5
6
7
#! /bin/sh

VERSION=$(echo 'ls pub/linux/kernel/v2.4/LATEST-IS-*' | lftp kernel.org)
VERSION=$(basename ${VERSION})
VERSION=$(echo ${VERSION} | cut -d - -f 3)

echo Latest stable Linux kernel release available on kernel.org is ${VERSION}
Pagina: 1