Page History
- Have a script in the correct run level linked to one in /etc/init.d which will do your job if it is present but allow the machine to come up for adjustments if not. (sample scripts below)
- Have a second disk configured in your VM which is used to place input data and extract output data
- Have patience as the job happens in a black box.
In order for this all to work you must have a VM which is rich enough to have "mkfs" which has the "-t vfat" option to make a windows vat32 partition.
Below is a suitable script for mounting a second disk at the right run level and deciding if a job should be run or the VM simply brought up for changes or inspection.
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/stata
case "$1" in
start)
echo "Testing VM Job Status"
mount /dev/hdb1 /vmjob
ls /vmjob
if test -f "/vmjob/statajob"
then
/vmjob/runstatajob.pl /vmjob statajob
shutdown -h now
else
echo "Bring up for non-vm work"
sleep 20
fi
echo "."
;;
esac
exit 0
Here is a perl script which mounts the second disk and looks for a file holding a list of Stata jobs to run.
#!/usr/bin/env perl
my $dir = $ARGV[0]; my $file = $ARGV[1];
chdir("/vmjob");
my $dbinstalllog = "stataVM.LOG";
print "Trying to open logfile... $dbinstalllog\n";
open(OLDOUT, ">&STDOUT");
open(OLDERR, ">&STDERR");
open(STDOUT, ">>$dbinstalllog") or die "Could not open $dbinstalllog: $!";
open(STDERR, ">&STDOUT");
select(STDERR);
$| = 1;
select(STDOUT);
$| = 1;
print "runstatajob.pl called with dir<$dir> file<$file>\n";
system("mkdir /tmp/vmjob");
system("cp * /tmp/vmjob");
#chdir($dir);
chdir("/tmp/vmjob");
print "Lets look at disk availability\n";
system("pwd");
system("df -h");
system("ls -l");
system("which stata-se");
print "Do the following job:\n";
print "*****************************\n\n";
system("cat $file");
print "*****************************\n\n";
# ado directory has to go in a stata "sysdir" # one such location is /usr/local/stata
# extract out ado.tar.gz
system("tar -zxvf ado.tar.gz");
system("chmod -R 777 ado");
system("cd ado");
system("mkdir /usr/local/ado");
# place in one of many sysdir directories
# visible by typing "sysdir" at the stata prompt
system("cp -r plus/* /usr/local/ado");
system("cp -r personal/* /usr/local/ado");
system("cd /tmp/vmjob");
open(JOB,"<$file") or die "Can not open <$file>:$!\n";
my $line = "";
while(<JOB>) {
chomp();
$line = $_;
print "Running stata on $line\n";
system("stata-se -b $line");
print "done\n";
system("ls");
}
close(JOB);
print "Copy results back to /vmjob\n";
system("cp *.log /vmjob");
[
