Expect script executes .pl before mount finishes

Hi,

I'm trying to mount machines that are 'ON' with an expect script. I would put these guys in fstab, but the virtual machine that runs script seems to freeze up/shutdown if one of the machines I'm trying to connect to is 'OFF'. Following the mount, I run a perl script that accesses the 'ON' machines and moves their data to the virtual machine.

My problem. Is when I execute the expect script
[1] the mount occurs (GOOD) (.sh)
[2] the perl script executes (GOOD) (.pl)
[3] no data transfers (BAD) (.pl)

Something that stumps me is that when I run the perl script by itself (and a machine is mounted). The data transfers. It is just when I run it in the expect script that it doesn't. So, it makes me believe it's something in my expect script. Everything executes in the expect script, so maybe the perl script is running before the mount complete? I put eof in there for that reason.....idk, that's why I'm here.

All in all I have three scripts.

The expect script.

#!/usr/local/bin/expect -f

spawn bash /dilts/AGIauto/mountcheck.sh
expect "*?assword for informatics:*" {send "password"}
expect eof

spawn perl /dilts/AGIauto/pullAGIdata.pl
expect eof

The shell script (does the mounting)

#!/bin/bash

#............................mount check
#.....AGI clinical
sudo mount -t cifs -o username=Ren_user,password=AIB#1109$,nounix,sec=ntlmssp  //10.204.129.234/Desktop /mnt/clin
ical/234mac

And the perl script (grabs/moves the data)

#!/usr/bin/perl

use strict;
use warnings;


#.....clinical (cln)
my $cln_MACdir233 = "/mnt/clinical/233mac";
my $cln_MACdir234 = "/mnt/clinical/234mac";
my $cln_WINdir243 = "/mnt/clinical/243win";

#.....molecular (mol)
my $mol_WINdir245 = "/mnt/molecular/245win";
my $mol_WINdir246 = "/mnt/molecular/246win";
my $mol_WINdir247 = "/mnt/molecular/247win";
my $mol_WINdir248 = "/mnt/molecular/248win";


my @WIN_AGIpaths = ($cln_WINdir243,
                $mol_WINdir245,
                $mol_WINdir246,
                $mol_WINdir247,
                $mol_WINdir248,
                );

my@MAC_AGIpaths = ($cln_MACdir233,$cln_MACdir234);


foreach my $path (@WIN_AGIpaths){

        opendir(DIR, $path) or die $!;

        while (my $f = readdir(DIR)) {

                next unless (-f "$path/$f");
                next unless ($f =~ m/^results/);
                my $result = "$path/$f";
                system("cp $result /dilts/AGIauto/pulleddata"); #change to 'mv'

        }

        closedir(DIR);
}

foreach my $path (@MAC_AGIpaths){

        opendir(DIR, $path) or die $!;
        while (my $d = readdir(DIR)) {

                next unless (-d "$path/$d");
                next unless ($d =~ m/^Reports_/);
                my $resultDIR = "$path/$d";


                        if (-e "$resultDIR/ResultsDet.txt"){

                                my $id;
                                if ($resultDIR =~/Reports_(.*)/){$id = $1;}
                                my $passname =  "/dilts/AGIauto/pulleddata/".$id."_ResultsDet.txt";
                                system("cp $resultDIR/ResultsDet.txt $passname"); #change to 'mv'
                        };
        }
        close(DIR);
}

Without spawning the perl script in your expect script, could you first check whether the bash scrpt could mount the cifs correctly. I have a feeling it the special characters of your password "AIB#1109$" that makes it fail.