[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [shell-script] chdir,opendir
From: |
Luiz Carlos Nebenzahl |
Subject: |
Re: [shell-script] chdir,opendir |
Date: |
Wed, 29 May 2002 21:28:45 -0300 |
Obrigado por responder!
O script esta em perl sim, te mando ele logo abaixo:
#!/usr/bin/perl
use Sys::Syslog;
$SophosRoot = "/usr/local/Sophos";
$IDELink = "/usr/local/Sophos/ide";
$VDLDir = "../lib";
#$Lynx = "/usr/local/bin/lynx -dump";
$Lynx = "/usr/bin/wget -q -O-"; # On Linux use this
$Unzip = "/usr/bin/unzip -joqq";
$rm = "/bin/rm";
$LockFile = "/tmp/SophosBusy.lock";
$LOCK_SH = 1;
$LOCK_EX = 2;
$LOCK_NB = 4;
$LOCK_UN = 8;
Sys::Syslog::openlog("Sophos-autoupdate", 'pid, nowait', 'mail');
# Work out the current VDL (and hence Sophos Sweep) version number
chdir "$SophosRoot/bin/$VDLDir";
opendir(LIBDIR, ".") || &BailOut("Cannot open Sophos/lib directory");
foreach $vdlname (sort readdir(LIBDIR)) {
next unless $vdlname =~ /^vdl-(\d+)\.(\d+)([a-z]?)\.dat$/;
$MajorVer = $1;
$MinorVer = $2;
$NSVFlag = $3;
}
closedir(LIBDIR);
&BailOut("Could not calculate Sophos version number")
unless defined($MajorVer) && defined($MinorVer);
$SophosVersion = "$MajorVer$MinorVer";
$VDLVersion = "$MajorVer.$MinorVer";
# Derive other variables, filenames and URLs from the version numbers
$ZipName = $SophosVersion . "_ides.zip";
$URL = "http://www.sophos.com/downloads/ide/$ZipName";
($min,$hour,$date,$month,$year) = (localtime)[1,2,3,4,5];
$month++;
$year+=1900;
$IDEDir = "$SophosRoot/$SophosVersion." . sprintf("%04d%02d%02d%02d%02d",
$year, $month, $date, $hour, $min);
# If the directory already exists, then we have already done the update
# for today, so quietly exit.
Sys::Syslog::syslog('info', "Sophos already up-to-date"),exit 0 if -d
$IDEDir;
# Create the IDE files directory
umask 0022;
mkdir $IDEDir, 0755;
chdir $IDEDir or &BailOut("Cannot cd $IDEDir, $!");
# Fetch and unpack the IDE zip file from Sophos
$result = system("$Lynx $URL > $ZipName");
&BailOut("Lynx failed with error return " . ($result>>8) . "\n") if
$result>>8;
$result = system("$Unzip $ZipName");
&BailOut("Unzip failed with error return " . ($result>>8) . "\n") if
$result>>8;
symlink("$VDLDir/vdl-$VDLVersion$NSVFlag.dat", "vdl.dat");
# Link in this new directory to Sophos
chdir $SophosRoot or &BailOut("Cannot cd $SophosRoot, $!");
$OldLinkTarget = readlink $IDELink;
&LockSophos();
unlink $IDELink if -l $IDELink;
symlink $IDEDir, $IDELink;
&UnlockSophos();
system("$rm -rf $OldLinkTarget") if defined $OldLinkTarget && -e
$OldLinkTarget;
Sys::Syslog::syslog('info', "Sophos successfully updated in $IDEDir");
Sys::Syslog::closelog();
exit 0;
sub BailOut {
Sys::Syslog::syslog('err', @_);
Sys::Syslog::closelog();
warn "@_, $!";
chdir $SophosRoot or die "Cannot cd $SophosRoot, $!";
system("$rm -rf $IDEDir") if -d $IDEDir;
exit 1;
}
sub LockSophos {
open(LOCK, ">$LockFile") or return;
flock(LOCK, $LOCK_EX);
print LOCK "Locked for updating Sophos IDE files by $$\n";
}
sub UnlockSophos {
print LOCK "Unlocked after updating Sophos IDE files by $$\n";
flock(LOCK, $LOCK_UN);
close LOCK;
}
----- Original Message -----
From: "Victor Pereira" <address@hidden>
To: <address@hidden>
Sent: Wednesday, May 29, 2002 9:11 PM
Subject: Re: [shell-script] chdir,opendir
> Luiz Carlos Nebenzahl wrote:
> >
> > Olá Lista!
> >
> > Alguem sabe que pacote ou .tar devo instalar no meu servidor para
conseguir os comandos, chdir ou opendir?
> > Estou tentando rodar a atualização automatica do Sophos, mas no script
ha este comandos que o meu CL7 não tem.
> > Obrigado!
> >
> > Luiz Carlos Nebenzahl
> > RotNet Sistemas e Conectividade
> >
> > [As partes desta mensagem que não continham texto foram removidas]
> >
>
> Ola Luiz, vc tem certeza q tail script nao esta em perl ?
> Digo isso pois chdir/opendir sao funcoes Perl/C relacionadas o
> filesystem
> man 2 chdir
> man 3 opendir
>
> []s
> VP
>
> --
> Quer a verdade ? Leia o codigo fonte
> -------------------------------------
> http://codigoaberto.org.br
> http://www.sourceforge.net
> http://www.cipsga.org.br
>
> ---------------------------------------------------------------------
> Esta lista não admite a abordagem de outras liguagens de programação, como
perl, C etc. Quem insistir em não seguir esta regra será moderado sem prévio
aviso.
> ---------------------------------------------------------------------
> Sair da lista: address@hidden
> ---------------------------------------------------------------------
> Esta lista é moderada de acordo com o previsto em
http://www.listasdiscussao.cjb.net
> ---------------------------------------------------------------------
>
> Seu uso do Yahoo! Grupos é sujeito às regras descritas em:
http://br.yahoo.com/info/utos.html
>
>
>