Guest wassup Posted February 23, 2009 Report Share Posted February 23, 2009 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! Quote Link to comment Share on other sites More sharing options...
neddie Posted February 23, 2009 Report Share Posted February 23, 2009 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? Quote Link to comment Share on other sites More sharing options...
Guest wassup Posted February 23, 2009 Report Share Posted February 23, 2009 yea, the point is to see when a folder is inserted, it will write the path and folder name to log.txt thats all that i need.. Quote Link to comment Share on other sites More sharing options...
theYinYeti Posted February 24, 2009 Report Share Posted February 24, 2009 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. Quote Link to comment Share on other sites More sharing options...
neddie Posted February 24, 2009 Report Share Posted February 24, 2009 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.