samba-mounted directory, OS X, bash, 'system' calls

J

John

Have got a Perl script called from within a bash script.
Bash connects to a Samba share:

umount ~/Documents/bin/pdfs
mount -t smbfs //NAME:pass@server/SHARE ~/Documents/bin/pdfs

Then it calls this Perl script:

#!/usr/bin/perl -w
my $sourcedir="~/Documents/bin/pdfs";
print "sourcedir=$sourcedir\n";
system("ls",$sourcedir);

I get:

ls: ~/Documents/bin/pdfs: No such file or directory

However if I copy the path from the error message and paste it onto
the command line behind 'ls' [ ls ~/Documents/bin/pdfs ], then the
shell lists the directory.

In an earlier try, I mounted the Samba volume via the Mac GUI and
pointed the script to something like /Volumes/pdfs. In that case it
found the files I was looking for.

Since I want this to run on a crontab and can't count on the volume
being mounted in the middle of a random night, I wanted to script the
Samba connection. Since I couldn't count on the volume NOT being
mounted either, I begin by unmounting anything that might already be
at that point.


John Campbell
 
J

John

Your shell is expanding ~/Documents/bin/pdfs into something like
/Users/jfcampbell/Documents/bin/pdfs.
You need to expand the '~'. The simplest way is probably

$sourcedir =~ s/^~/$ENV{HOME}/;

Or, I can spell out /Users/jfcampbell/Documents/bin/pdfs as a
constant.

Though I can't count on the Samba share being mounted all the time, I
can be reasonably sure the user name will be good for the life of the
script.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top