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
RADWHO(1)							 FreeRADIUS Daemon							 RADWHO(1)

NAME
radwho - show online users SYNOPSIS
radwho [-c] [-d raddb_directory] [-F radutmp_file] [-i] [-n] [-N nas_ip_address] [-p] [-P nas_port] [-r] [-R] [-s] [-S] [-u user] [-U user] [-Z] DESCRIPTION
The FreeRADIUS server can be configured to maintain an active session database in a file called radutmp. This utility shows the content of that session database. OPTIONS
-c Shows caller ID (if available) instead of the full name. -d raddb_directory The directory that contains the RADIUS configuration files. Defaults to /etc/raddb. -F radutmp_file The file that contains the radutmp file. If this is specified, -d is not necessary. -i Shows the session ID instead of the full name. -n Normally radwho looks up the username in the systems password file, and shows the full username as well. The -n flags prevents this. -N nas_ip_address Show only those entries which match the given NAS IP address. -p Adds an extra column for the port type - I for ISDN, A for Analog. -P nas_port Show only those entries which match the given NAS port. -r Outputs all data in raw format - no headers, no formatting, fields are comma-separated. -R Output all data in RADIUS attribute format. All fields are printed. -s Show full name. -S Hide shell users. Doesn't show the entries for users that do not have a SLIP or PPP session. -u user Show only those entries which match the given username (case insensitive). -U user Show only those entries which match the given username (case sensitive). -Z When combined with -R, prints out the contents of an Accounting-Request packet which can be passed to radclient, in order to "zap" that users session from radutmp. For example, $ radwho -ZRN 10.0.0.1 | radclient -f - radius.example.net acct testing123 will result in all an Accounting-Request packet being sent to the RADIUS server, which tells the server that the NAS rebooted. i.e. It "zaps" all of the users on that NAS. To "zap" one user, specifiy NAS, username, and NAS port: $ radwho -ZRN 10.0.0.1 -u user -P 10 | radclient -f - radius.example.net acct testing123 Other combinations are also possible. SEE ALSO
radiusd(8), radclient(1), radiusd.conf(5). AUTHOR
Miquel van Smoorenburg, miquels@cistron.nl. 17 Feb 2013 RADWHO(1)
All times are GMT -4. The time now is 05:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy