Pages

9/07/2007

Perl::Script::Cleanup Old Files


The following script will accept a list of folders and recursively look through each one for files older than a specified number of days.
A parameter file is used to provide input so it can be flexible after packaging with PerlPackager.

#cleanup.pl
use File::Find;
#get parameters
open (PRM, ";
close (PRM);
my $folder = $prm[0];
chomp $folder;
my @folder = split(/,/,$folder);
my $limit = $prm[1];
chomp $limit;
#Create log folder if it does not exist
if (not(-e "cleanup\\.")) {
mkdir ("cleanup");
}
#Name Log File
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime();
$m = sprintf("%0.2i", $mon+1);
$d = sprintf("%0.2i", $mday);
$y = $year + 1900 ;
$yy = substr($y, -2, 2);
$yy = sprintf("%0.2i", $yy);
$hh = sprintf("%0.2i", $hour);
$mm = sprintf("%0.2i", $min);
$ss = sprintf("%0.2i", $sec);
$T = "$y$m$d$hh$mm$ss" ;
$logfile=".\\cleanup\\$T.log";
open(LOG, ">$logfile");
print LOG "Cleanup run: $m\/$d\/$y $hh:$mm:$ss\n Folders: @folder\n Delete older than: $limit days\n";
print LOG "The following files, if any, have been deleted:\n";
find(\&CheckFile, @folder);
sub CheckFile {
if (not(-d $_)) {
if ($limit < (-M $_)) { $current = $File::Find::name; $current =~ tr/\//\\\\/; unlink $_; print LOG " $current\n"; } } } close (LOG);

The parameter file is below. It is setup to purge it's own log folder (.\cleanup) after the same number of days.

.\cleanup,c:\dev\purge\test\bak\1,c:\dev\purge\test\bak\2
10
#line 1 = comma separated list of folders to recursively search for old files.
#line 2 = number of days after which to delete files.

Perl::File Testing



# -o $file true if owned by EUID
# -e $file exists
# -z $file zero file
# -s $file non-zero file, returns size
# -r $file readable
# -w $file writeable
# -x $file executable
# -f $file plain file
# -d $file directory
# -l $file symbolic link
# -p $file named pipe or FIFO
# -S $file socket
# -b $file block special file
# -c $file character special file
# -T $file text file
# -B $file binary file
# -u $file setuid
# -g $file setgid
# -k $file sticky
# -t $file true if opened to a tty
# -M $file age in days since modified
# -A $file age in days since last accessed
# -C $file age in days since inode changed

9/04/2007

Windows::NTFS Permissions



From: Windows IT Library

NTFS Permissions and Files



NTFS
file permissions are used to control the access that a user, group, or
application has to files. This includes everything from reading a file to
modifying and executing the file. There are five NTFS file permissions:




  1. Read



  2. Write



  3. Read & Execute



  4. Modify



  5. Full Control



The five NTFS file permissions are also
listed in Table 1 with a description of the access that is allowed to the
user or group when each permission is assigned. As you can see, the permissions
are listed in a specific order. They all build upon each other.



















TABLE 1: NTFS FILE PERMISSIONS
NTFS
File Permission
 
   Allowed Access
Read
  This allows the user or group to read the file
and view its attributes, ownership, and permissions set.
Write
This allows the user or group to overwrite the
file, change its attributes, view its ownership, and view the permissions set.
Read
& Execute   
  This allows the user or
group to run and execute the application. In addition, the user can perform all
duties allowed by the Read permission.
Modify
This allows the user or group to modify
and delete a file including perform all of the actions permitted by the Read,
Write, and Read and Execute NTFS file permissions.
Full
Control
This allows the user or group
to change the permission set on a file, take ownership of the file, and perform
actions permitted by all of the other NTFS file permissions.




If a user needs all access to a file
except to take ownership and change its permissions, the Modify permission can
be granted. The access allowed by the Read, Write, and Read & Execute are
automatically granted within the Modify permission. This saves you from
assigning multiple permissions to a file or group of files. In later
discussions in this chapter you will see what happens when multiple NTFS file
permissions are assigned and applied and how you can determine the net access
the user or group has to that file or folder.








NOTE: A
file's attributes are properties of the file such as Read-Only, Hidden,
Archive, and System. The System attribute is usually applied only to operating
system boot files.




NTFS Permissions and Folders


NTFS Folder permissions allow what access is granted to a folder and the files and
subfolders within that folder. These permissions can be assigned to a user or
group. This topic defines each NFTS folder permission and its effect on a
folder. Table 2 displays a list of the NTFS file permissions and the access
that is granted to a user or group when each permission is applied.





















TABLE 2: NTFS FOLDER PERMISSIONS
NTFS
File Permission
    Allowed Access
Read
  This allows the user or group to view the
files, folders, and subfolders of the parent folder. It also allows the viewing
of folder ownership, permissions, and attributes of that folder.
Write
This allows the user or group to create new
files and folders within the parent folder as well as view folder ownership and
permissions and change the folder attributes.
List
Folder Contents
    This allows the user or
group to view the files and subfolders contained within the folder.
Read
& Execute
    This allows the user or
group to navigate through all files and subfolders including perform all
actions allowed by the Read and List Folder Contents permissions.
Modify
This allows the user to delete the folder
and perform all activities included in the Write and Read & Execute NTFS
folder permissions.
Full
Control
This allows the user or group
to change permissions on the folder, take ownership of it, and perform all
activities included in all other permissions.





Notice that the only major difference
between NTFS file and folder permissions is the List Folder Contents NTFS
folder permission. By using this NTFS folder permission you can limit the
user's ability to browse through a tree of folders and files. This is useful
when trying to secure a specific directory such as an application directory. A
user must know the name and location of a file to read or execute it when this
permission is applied to its parent folder.

Windows::NTFS Permissions



From: TechNet


Write Users can copy or paste new files and subfolders in the folder and change folder attributes. However, users cannot open or browse the folder unless you grant the Read permission. Assigning Write permission is useful for folders where users can file confidential reports, such as timesheets, that only the manager or shared folder administrator can read.

Read Users can see the names of files and subfolders in a folder and view folder attributes, ownership, and permissions. Users can open and view files, but they cannot change files or add new files. Assign the Read permission if users need only to read information in a folder and they do not need to delete, create, or change files.

List Folder Contents Users can see the names of files and subfolders in the folder. However, users cannot open files to view their contents.

Read & Execute Users have the same rights as those assigned through the Read permission, as well as the ability to traverse folders. Traverse folders rights allow a user to reach files and folders located in subdirectories, even if the user does not have permission to access portions of the directory path.

Modify Users can delete the folder and perform the actions permitted by the Write and Read & Execute permissions. Because Modify gives users the ability to delete the folder, use Modify permission only for administrators or for the group or department owner of the folder.

Full Control Users can change permissions, take ownership, delete subfolders and files, and perform the actions granted by all other permissions. Because Full Control gives users the ability to delete the folder, use Full Control permission only for administrators or for the group or department owner of the folder.

VOIP


Magic Jack - $40 for a year of phone service.

http://www.magicjack.com/site/index.html

This is interesting.