AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get file modification time (https://forums.alliedmods.net/showthread.php?t=192783)

draft 08-14-2012 01:35

Get file modification time
 
Hi, i want to make script that cleans old logs because im controlling more than 150 game servers and have to most of them only ftp access.
How can i get the file modification time in amxx? Or may be other solution?

DjOptimuS 08-14-2012 05:58

Re: Get file modification time
 
through AMXX i don't think it's posible, but with PERL it is. Here is a script i found some time ago on the internet

PHP Code:

#!/usr/bin/perl

use strict;
use 
Net::FTP;

my $host "ip";
my $dir "directory";
my $user 'username';
my $passwd "password";
my $interval 3600*24*7# 62 day
my $passive 1# my FTP server only works in PASV mode
my $DEBUG 0;

my $ftp Net::FTP->new($host,
Debug => $DEBUG,
Passive => $passive)
or die 
"Can't open $host\n";
$ftp->login($user$passwd) or die "Can't log in as $user\n";
$ftp->cwd($dir) or die "Can't chdir to $dir\n";
my @files $ftp->ls();

foreach 
my $file (@files) {
 
my $file_mdtm $ftp->mdtm($file) or die "Can't find $file in $dir\n";
 if (
time $file_mdtm >= $interval) {
 print 
"File $file is older than $interval secs: deleted\n";
 
$ftp->delete($fileunless $DEBUG;
 }



jimaway 08-14-2012 06:29

Re: Get file modification time
 
should be possible with sockets, since ftp servers should send date modified with file list
but without using ftp server with sockets i dont think its possible (unless you create somekind of module capable of doing that)

draft 08-14-2012 07:31

Re: Get file modification time
 
May be some PAWN script? Since AMXX uses pawn as basic language. I want to clean local logs (/amxmodx/logs/)

Waleed 08-14-2012 07:51

Re: Get file modification time
 
Why don't use PERL to clean logs.Use it as a server-side script, Let it access the directory then clean according to $interval time.It should work fine.

CS-A-Roland 08-14-2012 08:01

Re: Get file modification time
 
create a part in a webinterface where he gets all data of the server over a/the database and so also the /logs/ folder, then use php to delede all of the content in it!
So you can manage all over the www also with iphone or something else...
And there you can also create a list where you can set "delede" to on/off, intervalls and so on... realy flexible i think...

Arkshine 08-14-2012 08:17

Re: Get file modification time
 
There is no native for that, but you can, as another solution, create a small module with a new native which will return such time.

DjOptimuS 08-14-2012 09:06

Re: Get file modification time
 
why load the server more when you can use that tiny perl script ?

Arkshine 08-14-2012 09:14

Re: Get file modification time
 
That's not a small module which will change something but I agree he should use first the perl script as first solution if he can.

jimaway 08-14-2012 09:54

Re: Get file modification time
 
he said he has only ftp access to most of servers, how would you execute that perl script trough ftp? or trough amxx?


All times are GMT -4. The time now is 05:53.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.