Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
September 9, 2009, 10:38 pm
rate this thread
Have got a Perl script called from within a bash script.
Bash connects to a Samba share:
mount -t smbfs //NAME:pass@server/SHARE ~/Documents/bin/pdfs
Then it calls this Perl script:
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.
Re: samba-mounted directory, OS X, bash, 'system' calls
Your shell is expanding ~/Documents/bin/pdfs into something like
/Users/jfcampbell/Documents/bin/pdfs. Passing a list to system bypasses
the shell (normally a good thing) so ls ends up looking for a directory
called '~' under the current working directory.
You need to expand the '~'. The simplest way is probably
$sourcedir =~ s/^~/$ENV/;
though that won't respect the ~user/foo syntax. Another way would be
$sourcedir = glob $sourcedir;
which will expand ~user but will also expand other wildcards like *. I
don't know of any module that will just expand ~user and leave wildcards
alone, but it would be a pretty simple function to write using getpwnam.
- » SIGUSR1 ignored during poll() if sleep() and warn() called?
- — Next thread in » PERL Discussions
- » FAQ 4.18 Does Perl have a Year 2000 problem? Is Perl Y2K compliant?
- — Previous thread in » PERL Discussions