Any Perl gurus?

Associate
Joined
14 Dec 2003
Posts
2,149
Location
Malvern
Hey,

Been having a bit of trouble adapting a perl script that we have that creates a .call file and was wondering if anyone could lend a quick hand.

Code:
use File::Temp qw/ tempfile tempdir /;
use File::Copy;

my $fh = tempfile();
my ($fh, $filename) = tempfile(UNLINK => 1);

print "File handle is $fh  , File name is $filename\n\n";

printf $fh "Channel: SIP/$agent\n";
printf $fh "WaitTime: 30\n";
printf $fh "Context: from_sip\n";
printf $fh "Extension: $telenum\n";
close($fh);

my $destination = "/var/spool/asterisk/outgoing".substr($filename,4).".call";
print $destination;

move($filename, $destination) or die $1;

Now i'm trying to move the temp file from /tmp to /var but its not having it at all and from a bit of googling it looks as though its because there sat on 2 different partitions.

Now I should be able to create the temp file on /var but for some reason I just can't get my head around it.

Anyone able to help out?

Cheers,
Andy
 
Hey,

Been having a bit of trouble adapting a perl script that we have that creates a .call file and was wondering if anyone could lend a quick hand.

Code:
use File::Temp qw/ tempfile tempdir /;
use File::Copy;

my $fh = tempfile();
my ($fh, $filename) = tempfile(UNLINK => 1);

print "File handle is $fh  , File name is $filename\n\n";

printf $fh "Channel: SIP/$agent\n";
printf $fh "WaitTime: 30\n";
printf $fh "Context: from_sip\n";
printf $fh "Extension: $telenum\n";
close($fh);

my $destination = "/var/spool/asterisk/outgoing".substr($filename,4).".call";
print $destination;

move($filename, $destination) or die $1;

Now i'm trying to move the temp file from /tmp to /var but its not having it at all and from a bit of googling it looks as though its because there sat on 2 different partitions.

Now I should be able to create the temp file on /var but for some reason I just can't get my head around it.

Anyone able to help out?

Cheers,
Andy
Yeah what is the exact error you get?
 
I get the following,

Code:
Software error:
 at /var/www/html/perl/click2dial.pl line 54.

which refers to

51 my $destination = "/var/spool/asterisk/outgoing".substr($filename,4).".c all";
52 print $destination;
53
54 move($filename, $destination) or die $1;

Have chucked the whole file up here

Cheers!
 
do you get anything more useful by replacing $1 with $! and running the script?
 
oops..

Permission denied at /var/www/html/perl/click2dial.pl line 54.

Trying to copy from /tmp to /var/spool/asterisk/outgoing which have the following perms

drwxrwxrwt 8 root root 4096 Mar 4 00:06 tmp
drwx------ 2 root root 4096 Mar 3 16:31 outgoing

Scripts running under root as well.

/edit:

if i change it to a system("mv", $filename, $destination) or die $!; instead of the move() i dont get a permissions error but it just doesnt want to move the file.

Think i need to change it so that it creates the tempfile in a dir on /var but it doesn't want to accept the DIR => options :(
 
Last edited:
actually no need to worry now. I was using this script to generate a .call file which Asterisk would then parse to start a call. I've now switched to using the Manager API in Asterisk instead and its all sorted now.

Cheers,
 
Back
Top Bottom