Sponsored Content
Top Forums Shell Programming and Scripting How to check if a file is not readable by anyone except the owner? Post 302417187 by pseudocoder on Wednesday 28th of April 2010 09:37:26 PM
Old 04-28-2010
Absolutely
 

10 More Discussions You Might Find Interesting

1. Solaris

Owner of file gets 'not owner' error for chgrp

Hi Folks, I know that changing users and groups is pretty basic admin, but this one has got me stumped. When I try to change the group of a file for which I am the owner for, it still gives me a 'Not owner' error. For example, when I am logged in as 'webadmin', I have the following file: ... (4 Replies)
Discussion started by: brizrobbo
4 Replies

2. Shell Programming and Scripting

Shell script that would check if the CD-rom is readable

Hi, I was wondering if there's a command in Linux that would check to see if a CD is inserted into CD-rom. I am developing a shell script that would copy a file from CD rom. For this, I have to first verify if the CD has been inserted or not. Can anyone help me? Thanks, Sundeep (1 Reply)
Discussion started by: eamani_sun
1 Replies

3. HP-UX

file in malibox is readable format?

Hi, Files coming to mailbox are in readable format? Is there any special command to read these files. suppose i have sent a file like this megh$mailx -s "mesg" xyz@server.domain<file1.dat can xyz directly read the file from his mailbox? (1 Reply)
Discussion started by: megh
1 Replies

4. SuSE

Regarding Readable check for all the files in the folder

Currently we are doing the migration to unix to linux. I am facing the new problem kganeshb@its04489:~/scripts $ ls -l | more total 340 -rw-r----- 1 kganeshb users 9038 Oct 22 13:23 109_db.txt -rw-rw---- 1 dlc users 1413 Oct 10 17:40 1.txt -rw-rw---- 1 kganeshb users 45 Jan 28 13:46 a... (2 Replies)
Discussion started by: kingganesh04
2 Replies

5. UNIX for Advanced & Expert Users

How UNIX admin set up this? how files of 744 of other owner can be removed by another owner?

Hi all, We have some files are under 744 permissions and the the owner is say owner1 and group1. Now we have another user owner2 of group2, owner2 can remove files of the owner1 and the permission of those files are 744, unix admin told us he did some config at his side so we can do that. ... (14 Replies)
Discussion started by: TheGunMan
14 Replies

6. Shell Programming and Scripting

check whether file is readable or not in ksh

i want to check the readability of a file inside the script. when i use if then echo the file "$sourcef" is not readable else echo something fi i am getting the error : f: unknown test operator when i tried to check the availability with if i was... (3 Replies)
Discussion started by: gotam
3 Replies

7. Shell Programming and Scripting

check if file is readable by others

hi all, in ksh script how do i detect if a file is readable by others ?? thanks. (6 Replies)
Discussion started by: cesarNZ
6 Replies

8. Programming

writing to file is not readable by user

In the following code segment I write to some file using , but this write is not readable by me when i open the file. any helps would be thankful. #include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/types.h> #include<sys/stat.h> #include<errno.h> #include<fcntl.h>... (6 Replies)
Discussion started by: saman_glorious
6 Replies

9. Solaris

Privileges : modify dir/file owner by other that's not owner

i need to do the following operations in solaris 10: 1.change owner and group owner for files which are not owned by the current user and user group 2.to can delete files in the /tmp directory which are not of the current user 3. allow to a standard user the deletion of files in the /tmp... (1 Reply)
Discussion started by: sirmark
1 Replies

10. UNIX for Dummies Questions & Answers

How do I make this file readable/printable?

When I do the file I get ELF 32-bit MSB executable SPARC Version 1, dynamically linked, not stripped I am almost 100% sure I was able to print a readable version of this file in the past but I cannot remember how. Is it possible to convert this file into something that can be read and or... (3 Replies)
Discussion started by: fsanchez
3 Replies
Moose::Cookbook::Meta::Labeled_AttributeTrait(3)	User Contributed Perl Documentation	  Moose::Cookbook::Meta::Labeled_AttributeTrait(3)

NAME
Moose::Cookbook::Meta::Labeled_AttributeTrait - Labels implemented via attribute traits VERSION
version 2.0604 SYNOPSIS
package MyApp::Meta::Attribute::Trait::Labeled; use Moose::Role; Moose::Util::meta_attribute_alias('Labeled'); has label => ( is => 'rw', isa => 'Str', predicate => 'has_label', ); package MyApp::Website; use Moose; has url => ( traits => [qw/Labeled/], is => 'rw', isa => 'Str', label => "The site's URL", ); has name => ( is => 'rw', isa => 'Str', ); sub dump { my $self = shift; my $meta = $self->meta; my $dump = ''; for my $attribute ( map { $meta->get_attribute($_) } sort $meta->get_attribute_list ) { if ( $attribute->does('MyApp::Meta::Attribute::Trait::Labeled') && $attribute->has_label ) { $dump .= $attribute->label; } else { $dump .= $attribute->name; } my $reader = $attribute->get_read_method; $dump .= ": " . $self->$reader . " "; } return $dump; } package main; my $app = MyApp::Website->new( url => "http://google.com", name => "Google" ); SUMMARY
In this recipe, we begin to delve into the wonder of meta-programming. Some readers may scoff and claim that this is the arena of only the most twisted Moose developers. Absolutely not! Any sufficiently twisted developer can benefit greatly from going more meta. Our goal is to allow each attribute to have a human-readable "label" attached to it. Such labels would be used when showing data to an end user. In this recipe we label the "url" attribute with "The site's URL" and create a simple method showing how to use that label. META-ATTRIBUTE OBJECTS All the attributes of a Moose-based object are actually objects themselves. These objects have methods and attributes. Let's look at a concrete example. has 'x' => ( isa => 'Int', is => 'ro' ); has 'y' => ( isa => 'Int', is => 'rw' ); Internally, the metaclass for "Point" has two Moose::Meta::Attribute objects. There are several methods for getting meta-attributes out of a metaclass, one of which is "get_attribute_list". This method is called on the metaclass object. The "get_attribute_list" method returns a list of attribute names. You can then use "get_attribute" to get the Moose::Meta::Attribute object itself. Once you have this meta-attribute object, you can call methods on it like this: print $point->meta->get_attribute('x')->type_constraint; => Int To add a label to our attributes there are two steps. First, we need a new attribute metaclass trait that can store a label for an attribute. Second, we need to apply that trait to our attributes. TRAITS
Roles that apply to metaclasses have a special name: traits. Don't let the change in nomenclature fool you, traits are just roles. "has" in Moose allows you to pass a "traits" parameter for an attribute. This parameter takes a list of trait names which are composed into an anonymous metaclass, and that anonymous metaclass is used for the attribute. Yes, we still have lots of metaclasses in the background, but they're managed by Moose for you. Traits can do anything roles can do. They can add or refine attributes, wrap methods, provide more methods, define an interface, etc. The only difference is that you're now changing the attribute metaclass instead of a user-level class. DISSECTION
We start by creating a package for our trait. package MyApp::Meta::Attribute::Trait::Labeled; use Moose::Role; has label => ( is => 'rw', isa => 'Str', predicate => 'has_label', ); You can see that a trait is just a Moose::Role. In this case, our role contains a single attribute, "label". Any attribute which does this trait will now have a label. We also register our trait with Moose: Moose::Util::meta_attribute_alias('Labeled'); This allows Moose to find our trait by the short name "Labeled" when passed to the "traits" attribute option, rather than requiring the full package name to be specified. Finally, we pass our trait when defining an attribute: has url => ( traits => [qw/Labeled/], is => 'rw', isa => 'Str', label => "The site's URL", ); The "traits" parameter contains a list of trait names. Moose will build an anonymous attribute metaclass from these traits and use it for this attribute. The reason that we can pass the name "Labeled", instead of "MyApp::Meta::Attribute::Trait::Labeled", is because of the "register_implementation" code we touched on previously. When you pass a metaclass to "has", it will take the name you provide and prefix it with "Moose::Meta::Attribute::Custom::Trait::". Then it calls "register_implementation" in the package. In this case, that means Moose ends up calling "Moose::Meta::Attribute::Custom::Trait::Labeled::register_implementation". If this function exists, it should return the real trait's package name. This is exactly what our code does, returning "MyApp::Meta::Attribute::Trait::Labeled". This is a little convoluted, and if you don't like it, you can always use the fully-qualified name. We can access this meta-attribute and its label like this: $website->meta->get_attribute('url')->label() MyApp::Website->meta->get_attribute('url')->label() We also have a regular attribute, "name": has name => ( is => 'rw', isa => 'Str', ); Finally, we have a "dump" method, which creates a human-readable representation of a "MyApp::Website" object. It will use an attribute's label if it has one. sub dump { my $self = shift; my $meta = $self->meta; my $dump = ''; for my $attribute ( map { $meta->get_attribute($_) } sort $meta->get_attribute_list ) { if ( $attribute->does('MyApp::Meta::Attribute::Trait::Labeled') && $attribute->has_label ) { $dump .= $attribute->label; } This is a bit of defensive code. We cannot depend on every meta-attribute having a label. Even if we define one for every attribute in our class, a subclass may neglect to do so. Or a superclass could add an attribute without a label. We also check that the attribute has a label using the predicate we defined. We could instead make the label "required". If we have a label, we use it, otherwise we use the attribute name: else { $dump .= $attribute->name; } my $reader = $attribute->get_read_method; $dump .= ": " . $self->$reader . " "; } return $dump; } The "get_read_method" is part of the Moose::Meta::Attribute API. It returns the name of a method that can read the attribute's value, when called on the real object (don't call this on the meta-attribute). CONCLUSION
You might wonder why you'd bother with all this. You could just hardcode "The Site's URL" in the "dump" method. But we want to avoid repetition. If you need the label once, you may need it elsewhere, maybe in the "as_form" method you write next. Associating a label with an attribute just makes sense! The label is a piece of information about the attribute. It's also important to realize that this was a trivial example. You can make much more powerful metaclasses that do things, as opposed to just storing some more information. For example, you could implement a metaclass that expires attributes after a certain amount of time: has site_cache => ( traits => ['TimedExpiry'], expires_after => { hours => 1 }, refresh_with => sub { get( $_[0]->url ) }, isa => 'Str', is => 'ro', ); The sky's the limit! AUTHOR
Moose is maintained by the Moose Cabal, along with the help of many contributors. See "CABAL" in Moose and "CONTRIBUTORS" in Moose for details. COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Infinity Interactive, Inc.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.16.2 2012-09-19 Moose::Cookbook::Meta::Labeled_AttributeTrait(3)
All times are GMT -4. The time now is 01:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy