Solved

Simple Perl Script to remove folders in MAX OSX

Posted on 2013-06-27
6
234 Views
Last Modified: 2013-07-03
I need to do the following in a MAC terminal over and over as part of testing and want to include it in a .pl script:

#Remove Existing MySQL
sudo rm "/usr/local/mysql";
sudo rm -rf "/usr/local/mysql*";
sudo rm -rf "/Library/StartupItems/MySQLCOM";
sudo rm -rf "/Library/PreferencePanes/My*";
#sudo nano /etc/hostconfig  EDIT the MySQL bottom line out.
rm -rf "~/Library/PreferencePanes/My*";
sudo rm -rf "/Library/Receipts/mysql*";
sudo rm -rf "/Library/Receipts/MySQL*";
sudo rm -rf "/private/var/db/receipts/*mysql*";
#Removed Existing MySQL

How can I acheive that?  I tried with the syntax above, but it is obviously wrong.
0
Comment
Question by:weklica
  • 3
  • 2
6 Comments
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39283433
Why not just use a shell script?  Shell scripts pretty much use the same syntax as the command line.

If you really want to use a Perl script, this should work:
use strict;
use warnings;
foreach my $cmd (<DATA>) {
    next if ($cmd =~ m{^\s*#});
    system($cmd) == 0 or die "$cmd failed: $?";
}
__DATA__
#Remove Existing MySQL
sudo rm "/usr/local/mysql"
sudo rm -rf "/usr/local/mysql*"
sudo rm -rf "/Library/StartupItems/MySQLCOM"
sudo rm -rf "/Library/PreferencePanes/My*"
#sudo nano /etc/hostconfig  EDIT the MySQL bottom line out.
rm -rf "~/Library/PreferencePanes/My*"
sudo rm -rf "/Library/Receipts/mysql*"
sudo rm -rf "/Library/Receipts/MySQL*"
sudo rm -rf "/private/var/db/receipts/*mysql*"
#Removed Existing MySQL

Open in new window

0
 

Author Comment

by:weklica
ID: 39283439
I need to use perl because the rest of the script is in perl.  Do I need to do anything to isolate this from the rest of the script or just paste it above or below the rest of it?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39283453
The code you posted is shell commands, not Perl.  You can probably put it all in a shell script that you can call from Perl.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:weklica
ID: 39283462
I will just copy it above my perl script and hope it works.  not sure how to do anything in perl including the suggesting above, so i will let you know.  

Thanks
0
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 39283464
You could either create a shell script that you call from Perl (as DaveBaldwin said) or you could copy the code I provided in.

To copy my code into your script:
The part above __DATA__ can go anywhere
__DATA__ and below must go at the end of the script
If there is already a __DATA__ section in your script, it will not work

To write a shell script, create a new file with the below in it:
#!/bin/sh
#Remove Existing MySQL
sudo rm "/usr/local/mysql";
sudo rm -rf "/usr/local/mysql*";
sudo rm -rf "/Library/StartupItems/MySQLCOM";
sudo rm -rf "/Library/PreferencePanes/My*";
#sudo nano /etc/hostconfig  EDIT the MySQL bottom line out.
rm -rf "~/Library/PreferencePanes/My*";
sudo rm -rf "/Library/Receipts/mysql*";
sudo rm -rf "/Library/Receipts/MySQL*";
sudo rm -rf "/private/var/db/receipts/*mysql*";
#Removed Existing MySQL

Open in new window


And then put this in your Perl script:
# replace script.sh with whatever you named the file above
system("script.sh") == 0 or die "script.sh failed: $?";

Open in new window

0
 

Author Closing Comment

by:weklica
ID: 39297926
Thanks much!  Very helpful.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video discusses moving either the default database or any database to a new volume.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now