Jump to content

help translating perl to bash


Guest wassup
 Share

Recommended Posts

Hi everyone, i need to translate this perl script to bash, if someone could help me i would really appreciate it!

#!/usr/bin/perl

use strict;


my @data = `echo /home \`pwd\``;

my %data;
foreach my $line (@data){
chomp($line);
next if !$line;
$line =~ s/(\/cd.*?)$//;
$data{$line}++;
}
open(WRT," >> /home/user/log.txt");
foreach my $data (keys %data){
print WRT "$data\n";
}
close(WRT);

thanks in advance!

Link to comment
Share on other sites

Sorry, I don't quite get what this script is supposed to do. Do you know?

 

It looks like the first line builds a string like "/home /home/user/current/working directory"

But then when you loop through this, there's only one entry, which is the string itself, so there's no looping going on.

Then you do some replacing, deleting stuff which starts with /cd, and then you append that modified string to the log flie.

 

I don't get the point! :unsure: are you trying to list files here?

Link to comment
Share on other sites

I still don't get it. What I understand is that you want to be notified (in a log file) of new folders' creation under a given prefix. If that is so, I suggest you use inotifywatch in a bash script.

 

Yves.

Link to comment
Share on other sites

When you run that perl script on your machine, does it do what you want it to do? Because like I said, it doesn't appear to do what you want.

 

Have you tried something like

find /home/user/some/path -type d -mtime -2

to give a list of recently modified (not created) directories under the given path?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...