Thread: [openupload-devel] Deleting automatically files
Status: Beta
Brought to you by:
tsdogs
|
From: Sebastien S. <seb...@te...> - 2010-10-30 17:20:27
|
Hello I add the expires otion at 30 days, but i had to go on maintenance menu to delete them. I wrote a script to delete them by adding it on a cron job: #!/bin/bash find /var/www/openupload/data/ -type f -mtime +30 | xargs -r rm It's deleting the files but i have to delete too the entrance in the mysql db... any one have an idea of line I have to add ro my scripts? Many thx Sébastien Serre TEX ALLIANCE Logistic & IT Department Tél.+33.(1).56.77.30.11 Fax.+33.(1).76.50.82.23 seb...@te... |
|
From: Gregoire T. <gr...@cr...> - 2010-10-31 12:38:34
|
Hi Sebastien, I use the DBI library. You can write SQL request directly on PERL script. I use this method to delete expired files. Gregoire. 2010/10/30 Sebastien Serre <seb...@te...> > Hello > > I add the expires otion at 30 days, but i had to go on maintenance menu to > delete them. > > I wrote a script to delete them by adding it on a cron job: > > #!/bin/bash > > find /var/www/openupload/data/ -type f -mtime +30 | xargs -r rm > > > It's deleting the files but i have to delete too the entrance in the mysql > db... any one have an idea of line I have to add ro my scripts? > > Many thx > > > > Sébastien Serre > > TEX ALLIANCE > Logistic & IT Department > Tél.+33.(1).56.77.30.11 > Fax.+33.(1).76.50.82.23 > seb...@te... > > ------------------------------------------------------------------------------ > Nokia and AT&T present the 2010 Calling All Innovators-North America > contest > Create new apps & games for the Nokia N8 for consumers in U.S. and Canada > $10 million total in prizes - $4M cash, 500 devices, nearly $6M in > marketing > Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store > http://p.sf.net/sfu/nokia-dev2dev > _______________________________________________ > Openupload-devel mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openupload-devel > -- Cordialement, ___________________________ Grégoire Triquet C R E A T E I S tel : +336 747 744 54 email : gr...@cr... http://www.createis.com |
|
From: Sébastien S. <seb...@te...> - 2010-11-04 11:58:54
|
Hello Greg I'm not developper at all, could you please send me the script to delete? Many thx Sébastien Serre Logistic & IT dept Tex Alliance Tel: +33 1 56 77 30 11 Fax: +33 1 83 62 70 13 Le 30/10/2010 19:08, Sebastien Serre a écrit : > Hello > > I add the expires otion at 30 days, but i had to go on maintenance menu to delete them. > > I wrote a script to delete them by adding it on a cron job: > > #!/bin/bash > > find /var/www/openupload/data/ -type f -mtime +30 | xargs -r rm > > > It's deleting the files but i have to delete too the entrance in the mysql db... any one have an idea of line I have to add ro my scripts? > > Many thx > > > > Sébastien Serre > > TEX ALLIANCE > Logistic& IT Department > Tél.+33.(1).56.77.30.11 > Fax.+33.(1).76.50.82.23 > seb...@te... |
|
From: Gregoire T. <gr...@cr...> - 2010-11-04 12:21:08
|
Hi,
My script including lots of different things. I just give you a part of it.
It should help you :
----------------------------------------------
*#!/usr/bin/perl*
*
*
*use DBI;*
*use CGI;*
*
*
*# Définition des variables :*
*$database="";*
*$hostname="";*
*$login = "";*
*$mdp = "";*
*$chemin = "/var/www/openupload/";*
*$service = "[OPEN-UPLOAD]";*
*
*
*
*
*# On journalise dans les logs du système :*
*sub journalisation {*
* use Sys::Syslog qw( :DEFAULT setlogsock);*
* setlogsock('unix');*
* openlog($service,'','user');*
* syslog('info', $_[0]);*
* closelog;*
* *
* # On journalise ensuite dans les logs de la base de données :*
* journalisationBD();*
* }*
*
*
*# On journalise dans les logs de la BD :*
*sub journalisationBD {*
* $date2 = strftime ("%Y-%m-%d %H:%M:%S", localtime);*
* $requetelog = "INSERT INTO activitylog (level, log_time, ip,
user_login, module, realaction, plugin, result, moreinfo) VALUES
('notice','$date2','localhost','$proprio','crond','', 'expire','',
'$message')";*
* $preplog = $dbh->prepare($requetelog);*
* $preplog->execute;*
* }*
*
*
*# Gestion des courriels pour se faire avertir :*
*sub courriel {*
* $title='';*
* $to='';*
* $from= '';*
* $url = '';*
* $subject='';*
*
*
* open(MAIL, "|/usr/sbin/sendmail -t");*
*
*
* ## Mail Header*
* print MAIL "To: $to\n";*
* print MAIL "From: $from\n";*
* print MAIL "Subject: $subject\n\n";*
* ## Mail Body*
* print MAIL "";*
* close(MAIL);*
* }*
*
*
*# Début du script :*
*$dsn = "DBI:mysql:database=$database;host=$hostname";*
*$message = "[ERREUR] Echec de connexion à la base de données";*
*$dbh = DBI->connect($dsn, $login, $mdp) or die do journalisation($message);
*
*
*
*use POSIX qw(strftime);*
*my $date = strftime "%Y-%m-%d", localtime;*
*
*
*my @fichiersExpires_id;*
*
*
*$requete = "SELECT file_id FROM file_options WHERE module='expire' AND
value<'$date'";*
*$prep = $dbh->prepare($requete);*
*$message = "[ERREUR] Ne peux pas exécuter la requête de sélection
".$requete.".";*
*$prep->execute or die do journalisation($message);*
*
*
*while(my ($ids) = $prep->fetchrow_array){*
* push (@fichiersExpires_id, $ids);*
* }*
*
*
*my $fichiersExpires_nb=$prep->rows;*
*$prep->finish();*
*
*
*for ($i=0;$i<$fichiersExpires_nb;$i++){*
* $id_fichier = "SELECT id, user_login FROM files WHERE id LIKE
'$fichiersExpires_id[$i]%'";*
* $prep2 = $dbh->prepare($id_fichier);*
* $message = "[ERREUR] Ne peux pas exécuter la requête de sélection
$requete.";*
* $prep2->execute or die do journalisation($message);*
*
*
* my @fichiersEffaces_id;*
* my @fichiersEffaces_login;*
*
*
* while(my $sids = $prep2->fetchrow_arrayref()){*
* push (@fichiersEffaces_id, $sids->[0]);*
* push (@fichiersEffaces_login, $sids->[1]);*
* }*
* my $fichiersEffaces_nb=$prep2->rows;*
* $prep2->finish();*
*
*
* for ($j=0;$j<$fichiersEffaces_nb;$j++){*
* # on supprime toutes les entrées du fichier dans la base :*
* $requete = "DELETE files, file_options FROM files,
file_options WHERE files.id=file_options.file_id AND files.id =
'$fichiersEffaces_id[$j]'";*
* $prep3 = $dbh->prepare($requete);*
* $message = "[ERREUR] Ne peux pas exécuter la requête SQL de
suppression $requete.";*
* $prep3 -> execute or die do journalisation($message);*
* $prep3 -> finish;*
*
*
* # On récupère l'utilisateur dans user_login :*
* $proprio = $fichiersEffaces_login[$j];*
*
*
* # On journalise la bonne supression de l'entrée dans le
syslog :*
* $message = "[SUCCES] La valeur dans la base pour le fichier
$fichiersEffaces_id[$j] a été effacé.";*
* journalisation($message,$proprio);*
* # on supprime le fichier physiquement :*
* $message = "[ERREUR] Le fichier
$chemin$fichiersEffaces_id[$j] n'a pu être effacé.";*
* unlink($chemin.$fichiersEffaces_id[$j]) or die do
journalisation($message,$proprio);*
*
*
* # On journalise la bonne supression du fichier :*
* $message = "[SUCCES] Le fichier
$chemin$fichiersEffaces_id[$j] a été effacé.";*
* journalisation($message,$proprio);*
* }*
* }*
* *
*if ($fichierExpires_nb=="0"){*
* # On journalise la bonne supression du fichier :*
* $message = "[INFOS] Plus aucun fichier expiré sur le systême.";*
* journalisation($message);*
* }*
*
*
*$dbh -> disconnect;*
---------------------------------------
Regards,
Grégoire.
Le 4 novembre 2010 12:58, Sébastien Serre <seb...@te...> a
écrit :
> Hello Greg
>
>
> I'm not developper at all, could you please send me the script to delete?
>
> Many thx
> Sébastien Serre
> Logistic & IT dept
> Tex Alliance
> Tel: +33 1 56 77 30 11
> Fax: +33 1 83 62 70 13
>
> Le 30/10/2010 19:08, Sebastien Serre a écrit :
> > Hello
> >
> > I add the expires otion at 30 days, but i had to go on maintenance menu
> to delete them.
> >
> > I wrote a script to delete them by adding it on a cron job:
> >
> > #!/bin/bash
> >
> > find /var/www/openupload/data/ -type f -mtime +30 | xargs -r rm
> >
> >
> > It's deleting the files but i have to delete too the entrance in the
> mysql db... any one have an idea of line I have to add ro my scripts?
> >
> > Many thx
> >
> >
> >
> > Sébastien Serre
> >
> > TEX ALLIANCE
> > Logistic& IT Department
> > Tél.+33.(1).56.77.30.11
> > Fax.+33.(1).76.50.82.23
> > seb...@te...
>
>
> ------------------------------------------------------------------------------
> The Next 800 Companies to Lead America's Growth: New Video Whitepaper
> David G. Thomson, author of the best-selling book "Blueprint to a
> Billion" shares his insights and actions to help propel your
> business during the next growth cycle. Listen Now!
> http://p.sf.net/sfu/SAP-dev2dev
> _______________________________________________
> Openupload-devel mailing list
> Ope...@li...
> https://lists.sourceforge.net/lists/listinfo/openupload-devel
>
--
Cordialement,
___________________________
Grégoire Triquet
C R E A T E I S
tel : +336 747 744 54
email : gr...@cr...
http://www.createis.com
|
|
From: Mário R. G. <gin...@gm...> - 2010-11-04 14:17:25
|
Hi,
I prefer using openupload api... like this.
==== BEGIN - CUT HERE ====
<?
// Web app runexpire.php should be restricted to administrator in
Apache/IIS/etc config...
// 'runexpire.php?older=<days>' == <days> #days in database
if (! isset($_GET['older']) ) {
echo "You must inform # days (older var)...\n";
exit;
}
global $application;
$configfile = 'config.inc.php';
$configfile = 'www/'.$configfile;
if (file_exists($configfile)) {
require_once($configfile);
require_once($CONFIG['INSTALL_ROOT'].'/lib/general.inc.php');
$application = new Application($CONFIG);
$criteria[] = array('upload_date','<', date('Y-m-d',time()-($_GET['older']
* 24 * 60 * 60)));
$files = array();
$files = $application->db->readex('files',array($criteria));
if (count($files) <= 0) {
echo "No files selected to be removeed.\n";
$application->log('info','runexpire','','ALLOW','No file removed.');
exit;
}
foreach ($files as $f) {
$logstr = $f['name']. " (id:". $f['id'] . ", user: ".
$f['user_login'] ." included : ". $f['upload_date'] .")";
echo "File removed: " . $logstr . "\n";
filedelete($f['id'],$application);
$application->log('info','runexpire','','ALLOW','File removed:
'.$logstr);
}
} else {
echo "ERRO: Config file not found!.\n";
exit;
}
function filedelete($id,$application) {
$application->db->delete('files',array('id' => $id));
$application->db->delete('file_options',array('file_id' => $id));
unlink($application->config['DATA_PATH'].'/'.$id);
}
?>
==== EOF - CUT HERE ====
2010/10/30 Sebastien Serre <seb...@te...>
> Hello
>
> I add the expires otion at 30 days, but i had to go on maintenance menu to
> delete them.
>
> I wrote a script to delete them by adding it on a cron job:
>
> #!/bin/bash
>
> find /var/www/openupload/data/ -type f -mtime +30 | xargs -r rm
>
>
> It's deleting the files but i have to delete too the entrance in the mysql
> db... any one have an idea of line I have to add ro my scripts?
>
> Many thx
>
>
>
> Sébastien Serre
>
> TEX ALLIANCE
> Logistic & IT Department
> Tél.+33.(1).56.77.30.11
> Fax.+33.(1).76.50.82.23
> seb...@te...
>
> ------------------------------------------------------------------------------
> Nokia and AT&T present the 2010 Calling All Innovators-North America
> contest
> Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in
> marketing
> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
> http://p.sf.net/sfu/nokia-dev2dev
> _______________________________________________
> Openupload-devel mailing list
> Ope...@li...
> https://lists.sourceforge.net/lists/listinfo/openupload-devel
>
--
--
Mário Ginglass
|