Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simple Perl Script to remove folders in MAX OSX

Posted on 2013-06-27
6
Medium Priority
?
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 84

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Six Sigma Control Plans

715 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