Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sure! Here's a Perl script that should do what you're asking for:
- ```perl
- #!/usr/bin/perl
- use strict;
- use warnings;
- use File::Find;
- use File::Path qw(make_path);
- my $dir = '/';
- my $test_dir = '/home/liviu/test';
- my $test2_dir = '/home/liviu/test2';
- # Create directories if they don't exist
- make_path($test_dir) unless -d $test_dir;
- make_path($test2_dir) unless -d $test2_dir;
- find(\&wanted, $dir);
- sub wanted {
- # Replace 'log.problem' with 'log.fixed.forever'
- if (-f && -T) {
- open(my $fh, '<', $_) or die "Could not open file '$_' $!";
- my @lines = <$fh>;
- close($fh);
- my $changed = 0;
- for (@lines) {
- if (s/log\.problem/log.fixed.forever/g) {
- $changed = 1;
- }
- }
- if ($changed) {
- open(my $fh, '>', $_) or die "Could not open file '$_' $!";
- print {$fh} @lines;
- close($fh);
- symlink($File::Find::name, "$test_dir/$_");
- }
- }
- # Create symlink for files larger than 500MB
- if (-f && -s > 500 * 1024 * 1024) {
- symlink($File::Find::name, "$test2_dir/$_");
- }
- }
- ```
- This script will search inside all files of the system for `log.problem` and replace it with `log.fixed.forever`. It will also create a symlink of those files to `/home/liviu/test` folder. In the same script it will search for all files bigger than `500MB` and create a symlink to `/home/liviu/test2` folder. The folders will be created if they do not exist.
- Is there anything else you would like me to add to this script?
- To run the Perl script on Ubuntu, you need to follow these steps:
- 1. Open a text editor and paste the Perl script into it.
- 2. Save the file with a `.pl` extension, for example `script.pl`.
- 3. Open a terminal and navigate to the directory where you saved the script.
- 4. Make sure that Perl is installed on your system by running `perl -v`. If it's not installed, you can install it by running `sudo apt-get install perl`.
- 5. Make the script executable by running `chmod +x script.pl`.
- 6. Run the script with `sudo ./script.pl`.
- Please note that this script needs to be run with superuser privileges (`sudo`) because it needs to access all files on your system.
- Is there anything else you would like to know?
Advertisement
Add Comment
Please, Sign In to add comment