Pacific-Design.com

    
Home Index

1. Perl5

2. List Files

Perl5 / List Files /

List SQL Files and add them into Bash File

#!/bin/perl
#-----------------------------------------------------------------------------------#
open(my $fh, '>', 'run-sql.sh');

print $fh "#!/bin/bash\n";
print $fh "#---------------------------------------------------------------------#\n";
my @files = glob "/home/kevin/facebook_api/reports/*.sql";

for (0..$#files){

    print $fh 'echo "mysql -uroot -ppassword database < ' . $files[$_] . "\"\n";
    print $fh 'mysql -uroot -ppassword database < ' . $files[$_] . "\n\n";
}

print $fh "#---------------------------------------------------------------------#\n";

List Directories and Files

#!/usr/bin/perl
use strict;
use warnings;

#--------------------------------------------------------#
#  Written by Kevin Duraj
#--------------------------------------------------------#
my $hash_ref = {};
my @file     = `ps -e l`;

foreach my $line (@file)
{
    chomp $line;
    my @array = split(/\s+/, $line);

    my $pid  = $array[3];
    my $ppid = $array[4];
    my $name = $array[12];
    $hash_ref->{$pid}->{$ppid} = $name;
}

&print_hashes($hash_ref);

#--------------------------------------------------------#
sub print_hashes
{
    my $hash_ref = shift;

    for my $key1 (keys %$hash_ref)
    {
        print "\n$key1\n";

        for my $key2 (keys %{$hash_ref->{$key1}})
        {
            print " \\_ $hash_ref->{$key1}->{$key2}\n";
        }
    }
}

#--------------------------------------------------------#
__END__