Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A perl script for managing shared folders UNIX
When I first read the tip about sharing different folders, I thought surely someone will come out with something, and I was right, SharePoints came out, but it was lacking some functions I wanted, like restarting AppleShare.

So I started working on a tool in perl to take care of it for me until a newer version of SharePoints came out that would address these issues. While sharepoints is a great tool with a nice GUI, its new version still lacked this functionality, so I decided to post this one in case anyone wanted to use it.

Read the rest of this article if you'd like to see the script and how to use it...

Here is what you get when you don't give it any options:
[user @machine]% ./appleshare
Usage: appleshare {add|delete|list} {share name} {path} {owner|everyone} {full|readonly}
And here is an example of sharing a folder that only the owner has access to:
[user @machine]% ./appleshare add pictures /Users/user/Pictures owner
And here is an example of sharing a folder that anyone has readonly access to:
[user @machine]% ./appleshare add pictures /Users/user/Pictures everyone readonly
Owner is assumed to have full access unless readonly is specified. Here is an example of how to delete a shared folder:
[user @machine]% ./appleshare delete pictures
Here is an example of how to list the currently shared folders:
[user @machine]% ./appleshare list
Creating the script
Paste the following into a text file, name it, then open a terminal and "chmod filename 755" so that it's executable.

$usage= "Usage: appleshare {add|delete|list} {share name} {path} {owner|everyone} {full|readonly}\n\n";
if (! $ARGV[0]) {die "$usage";}

if ($ARGV[3] eq "" || $ARGV[3] eq "owner") {
} elsif ($ARGV[3] eq "everyone") {
if ($ARGV[4] eq "full") {
} else {
die "$usage";
if ($ARGV[0] eq "add") {
} elsif ($ARGV[0] eq "delete") {
} elsif ($ARGV[0] eq "list") {
} else {
print "Invalad arguments. $usage";
exit 0;

sub add {
system ("/usr/bin/sudo /usr/bin/nicl / -create /config/SharePoints/$ARGV[1]");
system ("/usr/bin/sudo /usr/bin/nicl / -append /config/SharePoints/$ARGV[1] directory_path $ARGV[2]");
system ("/usr/bin/sudo kill -HUP `cat /var/run/`");
system ("/usr/bin/sudo /bin/chmod $mode $ARGV[2]");
print "Added AppleShare mount of $ARGV[1]\n";
sub delete {
system ("/usr/bin/sudo /usr/bin/nicl / -delete /config/SharePoints/$ARGV[1]");
system ("/usr/bin/sudo kill -HUP `cat /var/run/`");
print "Deleted AppleShare mount of $ARGV[1]\n";
print "If you shared this with full access for everyone, you may want to fix\nyour permissions on the directory involved.\n";
sub list {
system ("/usr/bin/sudo /usr/bin/nicl / -list /config/SharePoints/");

sub restart_ATS {
@processes = `/usr/bin/sudo ps -xco pid,command`;
foreach $process (@processes) {
if ($process =~ "AppleFileServer") {
$process =~ s/AppleFileServer//g;
chomp $process;
system ("/usr/bin/sudo kill -9 $process");
print "Restarting AppleTalk service...\n";
system ("/usr/bin/sudo /usr/sbin/AppleFileServer &");

  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)

A perl script for managing shared folders | 0 comments | Create New Account
Click here to return to the 'A perl script for managing shared folders' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.