-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstatamphup
executable file
·72 lines (58 loc) · 2.04 KB
/
statamphup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
# statamphup will prepare and submit a Stata-MP job and email the user when it
# is finished
# Test usage; if incorrect, output correct usage
if [ "$#" -ne 1 ]; then
echo "********************************************************************"
echo "* Statamphup version 2.0 *"
echo "********************************************************************"
echo "The 'statamphup' script submits Stata-MP batch jobs using nohup."
echo ""
echo "Usage is:"
echo " statamphup <stata_do_file.do>"
echo ""
echo "Spaces in the filename or directory name may cause failure."
echo ""
else
# Stem and extension of file
filestem=`echo $1 | cut -f1 -d.`
extension=`echo $1 | cut -f2 -d.`
# Test if file exist
if [[ ! -r $1 ]]; then
echo ""
echo "File does not exist"
echo ""
elif [[ $extension != do ]]; then
echo ""
echo "Invalid input file, must be an m-file"
echo ""
else
# Direct output
output=$filestem.log
echo "stata: directing output to $output"
# Use user-defined 'TMPDIR' if possible; else, use /tmp
if [[ -n $TMPDIR ]]; then
pathy=$TMPDIR
else
pathy=/tmp
fi
# Tempfile to enable emailing content
timer=`mktemp $pathy/timer.XXXXXX` || exit 1
chmod 600 $timer
# Tempfile for the script
shell=`mktemp $pathy/shell.XXXXXX` || exit 1
chmod 700 $shell
# Create email body: path, filename, and start time
starter=`date`
echo "$PWD/$1 finished" >> $timer
echo "$starter S" >> $timer
# Create script; add end time to email subject
echo "#!/bin/sh" >> $shell
echo "time -p stata-mp -b do $1 " >> $shell
echo "date >> $timer" >> $shell
echo "mutt -s \"$1 finished\" -a $output nohup.out -- [email protected] < $timer" >> $shell
nohup $shell &
# Nohup takes a split second longer than other commands
sleep 0.01s
fi
fi