lamar1
asked on
Delete VBS Files
I need a script of some sort that will find all .vbs files on a server and delete them, would perfer to run remotely. I do need a log file..need ASAP and am willing to pay the points to get it...Thanks
Lamar
Lamar
ASKER
I need it for NT, will it work?
with minor modifications, it will.
also let me know about the search location (entire server/only certain dir).
you have posted this question twice. pl delete one of them.
also let me know about the search location (entire server/only certain dir).
you have posted this question twice. pl delete one of them.
ASKER
I need it to search the entire server, drives C,E,G,H,I,J the last 4 drives are 130gb drives.
Server name DMOS2
Thanks
Server name DMOS2
Thanks
Depending on what kind of speed that you require, you may want to use something faster than perl.
You are probably better off running with what maneshr has but since I already have this around...
If time is not critical, perl is about as fast as they come for development...
A simple script that I use to wipe my bak files follows:
# By Andrew D. Pitonyak
# pitonyak@bigfoot.com
use strict;
use LogFile;
my $my_log = new LogFile;
$my_log = new LogFile;
$my_log->log_front("DelSpe
$my_log->screen_echo(1);
sub dumb_del($$)
{
my ($dir_name, $wild_card) = @_;
foreach (grep(-f $_, glob("$dir_name$wild_card"
{
$my_log->write_log("W", 10, "$_");
#
# You really should do some more here to check the status to
# see if you can delete it. If not you should set it so that
# you can.
#
unlink($_);
}
foreach (grep(-d $_, glob("$dir_name\*")))
{
dumb_del("$_\\", $wild_card);
}
}
sub smart_recursive_del($)
{
my $dir_name = shift;
my $wild_card = '*.bak';
if (not -d $dir_name)
{
print "Directory $dir_name does not exist\n";
}
else
{
$dir_name .= '\\' if $dir_name !~ /\\$/;
$my_log->write_log("I", 1, "Deleting file spec $wild_card from $dir_name");
dumb_del($dir_name, $wild_card);
}
}
foreach (@ARGV) {
smart_recursive_del($_);
}
I ran the program as
perl -w DelSpec.pl \devsrc
You would need to give the list of all your directories that you wanted scanned such as
perl -w DelSpec.pl c:\ d:\ e:\ f:\
Of course you do not have my log routines which produced a log by the name
DelSpec.20000504.2142.log
Which gives me a time date stamp in the file name as
DelSpec.YYYYMMDD.hhmm.log
If you need it I can send you the libraries but you could also simply open a file
and simply dump the data to it. The output follows.
This includes a time date stamp for each action.
DelSpec-I-0001-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
DelSpec-W-0010-20000504.21
use File::Find;
find(sub{/\.vbs$/ && (unlink($_) || warn "$name: $!")},qw(C: E: G: H: I: J:));
find(sub{/\.vbs$/ && (unlink($_) || warn "$name: $!")},qw(C: E: G: H: I: J:));
ASKER
I'll have to check these out and let you know.
ozo I get the following when your script starts.
Name "mani::name" used only once: possible type at find.pl line 2.
Lamar
ozo I get the following when your script starts.
Name "mani::name" used only once: possible type at find.pl line 2.
Lamar
ASKER
maneshr, what happened to you, I was expecting you to post your script Lamar
ASKER
TYPO of my own.
I'll have to check these out and let you know.
ozo I get the following when your script starts.
Name "main::name" used only once: possible type at find.pl line 2.
Lamar
I'll have to check these out and let you know.
ozo I get the following when your script starts.
Name "main::name" used only once: possible type at find.pl line 2.
Lamar
ASKER
Typo of my own (part 2)
I'll have to check these out and let you know.
ozo I get the following when your script starts.
Name "mani::name" used only once: possible typo at find.pl line 2.
Lamar
I'll have to check these out and let you know.
ozo I get the following when your script starts.
Name "mani::name" used only once: possible typo at find.pl line 2.
Lamar
lamar1,
here is the quick-n-dirty solution that i have.
===============my_del.pl
$|++;
## Add the drives you want to delete from here.
@drives=("c","D");
## specify the type of files you want to delete
$pattern="*.vbs";
foreach $drive (@drives){
$tmp=$drive.":\\".$pattern ;
$var=`dir $tmp /s`;
@var=split(/\n/,$var);
foreach(@var){
if (/\s+Directory of(.*)/){
$cur_dir=$1;
}
if (/^\d{2}\/\d{2}\/\d{2}\s+\ d+:\d+.\s+ (.*)/){
($size,$file_name)=split(/ \s+/,$1,2) ;
$file_to_be_deleted=$cur_d ir."\\".$f ile_name." \n";
`del /p $file_to_be_deleted 2> null`;
push(@deleted_files,$file_ to_be_dele ted);
}
}
}
## Write the list of files that matched your pattern in the log file.
open(LOG,">>/temp/log") || die $!;
foreach(@deleted_files){
print LOG $_;
}
close(LOG);
here is the quick-n-dirty solution that i have.
===============my_del.pl
$|++;
## Add the drives you want to delete from here.
@drives=("c","D");
## specify the type of files you want to delete
$pattern="*.vbs";
foreach $drive (@drives){
$tmp=$drive.":\\".$pattern
$var=`dir $tmp /s`;
@var=split(/\n/,$var);
foreach(@var){
if (/\s+Directory of(.*)/){
$cur_dir=$1;
}
if (/^\d{2}\/\d{2}\/\d{2}\s+\
($size,$file_name)=split(/
$file_to_be_deleted=$cur_d
`del /p $file_to_be_deleted 2> null`;
push(@deleted_files,$file_
}
}
}
## Write the list of files that matched your pattern in the log file.
open(LOG,">>/temp/log") || die $!;
foreach(@deleted_files){
print LOG $_;
}
close(LOG);
ASKER
I'll test it and let you know, thanks for your efforts..Lamar
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Follow this link to download a program that will erase the Loveletter virus and the files overwritten by it
http://www.atremo.se/loveletter/clean.vbs
Doubleklick to execute it
http://www.atremo.se/loveletter/clean.vbs
Doubleklick to execute it
ASKER
Why would I want a virus cleaner, this is not what I asked for, this is for something entirely different, I have some mis-behaving vbs scripts that I can't pinpoint and need to remove them so I can do a restore from a know good set of backups, before the problem started...Thanks anyway.
Adding case independence, logging output (to stdout) and removing the compile error from ozo's answers follows:
use File::Find;
find(sub{/\.vbs$/i && (print "$File::Find::name\n") && (unlink($_) || warn "$File::Find::name: $!")},qw(C:\ E:\ H:\ I:\ J:\));
You'll get a line for each file deleted and possibly a line if there was an error deleting it.
use File::Find;
find(sub{/\.vbs$/i && (print "$File::Find::name\n") && (unlink($_) || warn "$File::Find::name: $!")},qw(C:\ E:\ H:\ I:\ J:\));
You'll get a line for each file deleted and possibly a line if there was an error deleting it.
ASKER
Worked fine, thanks for your help...Lamar
lamar1,
Glad to know that your problem was resolved.
Rgds
Glad to know that your problem was resolved.
Rgds
what os do you have?? (UN*X or Win* or others)
i have a script for UNIX that does what you want. i will also add the log feature to it, so that it fits your requirement.