Sponsored Content
Top Forums Shell Programming and Scripting glob not matching all files in perl Post 302608547 by odyssey on Saturday 17th of March 2012 10:43:18 PM
Old 03-17-2012
glob not matching all files in perl

I encountered a weird issue with globbing in perl not returning all files, while I was testing out a script for recursive dir-processing on my Synology NAS.

Basically it didn't show (/match?) all the files in a specific directory. If I move the file to a different directory or even rename it, it STILL doesn't show, as if something is wrong with the file.

If I copy the file to a new file, neigher of the files are showing.

I can pipe more data into the file and touch it - It doesn't make a difference until I create a new file (e.g. pipe new data into it, thus overwriting it):

Code:
/volume1/share/script # ls -l /volume1/share/testdir/
-rwxrwxrwx    1 admin    users            0 Mar 18 02:33 testfile1
-rwxrwxrwx    1 admin    users    7659671691 Mar 18 03:05 testfile2
 
 
/volume1/share/script # perl -e 'foreach (</volume1/share/testdir/*>) { print $_,"\n"; }'
/volume1/share/testdir/testfile1
 
 
/volume1/share/script # touch /volume1/share/testdir/testfile2
 
 
/volume1/share/script # perl -e 'foreach (</volume1/share/testdir/*>) { print $_,"\n"; }'
/volume1/share/testdir/testfile1
 
 
/volume1/share/script # echo "more data" >> /volume1/share/testdir/testfile2
 
 
/volume1/share/script # perl -e 'foreach (</volume1/share/testdir/*>) { print $_,"\n"; }'
/volume1/share/testdir/testfile1
 
 
/volume1/share/script # echo "new data" > /volume1/share/testdir/testfile2  
 
 
/volume1/share/script # perl -e 'foreach (</volume1/share/testdir/*>) { print $_,"\n"; }'
/volume1/share/testdir/testfile1
/volume1/share/testdir/testfile2

This has caused some serious headscratching... The closest thing I got while googling, was someone claiming that glob is heavily buggy.

I'm open to alternatives, but I hope they are not too different, since I've already made a pretty huge script based on the browse-function. I guess I could simply call the 'ls' command itself, but it would be nice to have something more perl-native.

Since I can't post URL's yet, I'll paste the browse script here (for good measure):
Code:
sub browse($);

sub browse($)
{
    my $path = $_[0];

    if($path !~ /\/$/)
    { $path .= '/'; }

    for my $eachFile (glob($path.'*'))
    {

        if(-d $eachFile)
        { browse($eachFile); }
        else
        { print "$eachFile\n"; }
    }
}

browse("/volume1/share/testdir/");


Last edited by odyssey; 03-17-2012 at 11:51 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl IO vs GLOB symbols

Hi, Can someone please clarify how we are able to use both IO and GLOB symbols of a package variable interchangeably? Please consider the following code: open(FH,"myfile") || die "Unable to open file myfile:$@"; my $glob_var = *main::FH{GLOB}; my $io_var = *main::FH{IO}; print $glob_var... (0 Replies)
Discussion started by: srinivasan_85
0 Replies

2. Programming

How to find the matching data b/w 2 files in perl?

Hi friends,, i have find the matching data between 2files. My file1 have a data like rs3001336 rs3984736 rs2840532 File2 have a data like rs3736330 1 2359237 A G 0.28 1.099 0.010 rs2840532 1 2359977 G A 0.363 0.3373 1.123 rs3001336 1 2365193 G A 0.0812 0.07319 1.12 ... (1 Reply)
Discussion started by: sureshraj
1 Replies

3. Shell Programming and Scripting

How to find the matching data b/w 2 files in perl?

Hi friends,, i have find the matching data between 2files. My file1 have a data like rs3001336 rs3984736 rs2840532 File2 have a data like rs3736330 1 2359237 A G 0.28 1.099 0.010 rs2840532 1 2359977 G A 0.363 0.3373 1.123 rs3001336 1 ... (4 Replies)
Discussion started by: sureshraj
4 Replies

4. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense. ... (4 Replies)
Discussion started by: kittyluva2
4 Replies

5. Shell Programming and Scripting

Need to extract only decimal numbers for a glob of text

If you have a look at this thread, you'll see that users have been posting the output a script which are numbers that range from 2 to 5 decimal places. If I dump this entire thread to txt file, how can I: 1) Delete everything except for numbers of the following formats (where 'x' is a digit and... (5 Replies)
Discussion started by: graysky
5 Replies

6. Shell Programming and Scripting

Python - glob () - How to grep same files with different extension files

Hi I Have a directory and i have some files below abc.txt abc.gif gtee.txt ghod.pid umni.log unmi.tar How can use glob function to grep abc files , i have created a variable "text" and i assigned value as "abc", please suggest me how can we use glob.glob( ) to get the output as below... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

7. Shell Programming and Scripting

Using glob() in python script in Linux

Hi I need some suggestion on glob function. I am trying to write a python program to grep some specific files in a particular directory. In the directory i have some files like below abc.log abc.pid abc.tar gadd.tar gat.log gat.tar in this directory i need to grep onlu my hostname files,... (1 Reply)
Discussion started by: kumar85shiv
1 Replies

8. Shell Programming and Scripting

Perl - Use of *? in Matching Pattern

I am using Perl version 5.8.4 and trying to understand the use of regular expression. Following is my code and output. $string = "Perl is a\nScripting language"; ($start) = ($string =~ /\A(.*?) /); @lines = ($string =~ /^(.*?) /gm); print "First Word (using \\A): $start\n","Line... (4 Replies)
Discussion started by: jnrohit2k
4 Replies

9. Shell Programming and Scripting

Use ./*glob*

I used this site to check a script. ShellCheck - shell script analysis tool Line 57: zip -u -q Desktop_Items.zip *.desktop ^-- SC2035: Use ./*glob* or -- *glob* so names with dashes won't become options. I do not understand what is wrong with my zip... (6 Replies)
Discussion started by: drew77
6 Replies

10. Shell Programming and Scripting

Issue with user input including * (glob) and sed

Hello All, I have created a script that searches for different things and "sanitizes" the findings from files. Currently the user is required to put in a hostname (server.serverfarm.abc) one at a time to replace. I would like the user be able to use *.*.abc in grep and then pipe into sed to... (1 Reply)
Discussion started by: jvezinat
1 Replies
mkcdsl(8)						      System Manager's Manual							 mkcdsl(8)

NAME
mkcdsl - Make a context-dependent symbolic link (CDSL) SYNOPSIS
/usr/sbin/mkcdsl [-bfnqv] [-i | -c | -a] [sourcename] [targetname] OPTIONS
All members. Copy the existing file or directory to a member-specific area on all members. Boot partition. In a cluster, the CDSL is placed on the boot partition. On a standalone system, an entry in added to the CDSL inventory file, and the CDSL will be created on the boot partition when the system is converted to a cluster by running clu_create. Copy the existing file or directory to a member-specific area on this member only. Force the overwriting of the existing CDSL or member-specific file or directory. When the force option is used with a copy option, mkcdsl will overwrite an existing member-specific file or directory. Without the force (-f) option, mkcdsl issues an error or message whenever the physical path of the target differs from the specified targetname (for example, when targetname resolution traverses a symbolic link), or when the source for a specified copy option cannot be found. Unless the -f option is specified, mkcdsl will exit when it encounters a situation that would generate an error message. The mkcdsl command issues a warning message if the specified sourcename differs from the calculated sourcename. However, you do not need the -f option to stop mkcdsl from exiting when it encounters a situation that generates a warning message. Inventory only. Check the files and update the inventory: If targetname is a CDSL, add a new entry or update the existing entry in /var/adm/cdsl_admin.inv. If targetname is not a CDSL or does not exist, remove its entry from /var/adm/cdsl_admin.inv. No execute mode. Display what would be done but do not create or change anything. Quiet. Stdout and stderr are redirected to /dev/null. Verbose. The pathname of the member-specific file to be linked. By default, each CDSL created by mkcdsl has a sourcename that points to the default member-specific area in the file system where the targetname resolves. For example, /usr/cluster/mem- bers/{memb}/ is the default member-specific area for the /usr file system. When issued without an explicit sourcename, mkcdsl creates a sourcename that points to this default member-specific area using a relative pathname. In most cases, this default behavior is satisfac- tory. It creates a relative link that resolves properly regardless of where the file system is mounted. If you specify a sourcename, mkcdsl uses this value as the pathname to the member-specific file or directory. The sourcename must include the member-context path compo- nent {memb}. The pathname of the new CDSL entry to be created. If targetname exists, the -f, -c or -a options are required. If the reso- lution of the targetname traverses any symbolic links or file system mount points, the default value of sourcename is adjusted such that the member-specific files are placed in the same file system to which targetname resolves. DESCRIPTION
A context-dependent symbolic link (CDSL) is a special form of a symbolic link, described in ln(1), whose target pathname includes a vari- able ({memb}). The value of {memb} is determined during pathname resolution, making it possible to maintain member-specific configuration and data files within the clusterwide namespace. The mkcdsl command creates a CDSL, effectively making the specified targetname file or directory member-specific. The command simplifies the creation of a CDSL by automatically calculating a default sourcename, which resolves to the default member-specific area in the file system where the CDSL is created. When mkcdsl creates a CDSL, it adds an inventory entry to a clusterwide CDSL inventory file, /var/adm/cdsl_admin.inv. This entry makes it possible for the cdslinvchk command to check CDSLs created by mkcdsl. The mkcdsl -i option updates the inventory file to reflect the cur- rent state of the CDSL by adding, modifying, or removing entries from the CDSL inventory file. In a cluster, when directed to put a file in a member-specific directory (-c or -a), mkcdsl populates both the member-specific directory or directories and the member0 directory. Although you can run mkcdsl from the command line, the mkcdsl command is designed to be non-interactive; it can be called from scripts without requiring user input to complete a task. EXAMPLES
To create a CDSL, /usr/testfile that points to cluster/members/{memb}/testfile: # mkcdsl /usr/testfile # ls -l /usr/testfile ... /usr/testfile -> cluster/members/{memb}/testfile In the previous example, /usr/testfile must not exist. The CDSL is created in /usr and no files are created in any member's /usr/clus- ter/members/{memb} directory. To copy the existing file or directory /usr/testfile1 to this member's /usr/cluster/members/membern directory and replace it with a CDSL that points to cluster/members/{memb}/testfile1: # mkcdsl -c /usr/testfile1 Although the CDSL references all members, only this member has a copy of the original /usr/testfile1 file. To copy the existing file or directory /usr/testfile2 to all members' /usr/cluster/members/{memb} directories and replace it with a CDSL that points to cluster/members/{memb}/testfile2: # mkcdsl -a /usr/testfile2 All members have a copy of the original /usr/testfile2 file. To create a CDSL and explicitly specify the sourcename: # mkcdsl /usr/share/cluster/members/{memb}/testfile3 /usr/share/doclib/testfile3 *** Warning *** The passed source name, '/usr/share/cluster/members/{memb}/testfile3' differs from the calculated source name: cluster/mem- bers/{memb}/testfile3 Using passed source name: '/usr/share/cluster/members/{memb}/testfile3' Because the specified sourcename differs from mkcdsl's calculated default value, the command issues a warning message. Note that mkcdsl makes the CDSL. The mkcdsl command does not exit on a warning message. It will exit for an *** Error *** message unless the -f option is specified. To add an inventory record for an existing CDSL to the /var/adm/cdsl_admin.inv file: # mkcdsl -i /etc/testfile4 To remove a CDSL and then remove its entry from the /var/adm/cdsl_admin.inv file: # rm /etc/testfile4 # mkcdsl -i /etc/testfile4 Note that removing the CDSL and its entry does not remove any files referenced by the CDSL. EXIT STATUS
The exit values for mkcdsl are: Success. Failure. FILES
Specifies the command path. CDSL administrative inventory file. This file will not exist on all systems. SEE ALSO
Commands: ln(1), cdslinvchk(8) Files: local(4) Miscellaneous: hier(5) mkcdsl(8)
All times are GMT -4. The time now is 01:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy