-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmathup
executable file
·86 lines (75 loc) · 2.56 KB
/
mathup
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
# mathup will prepare and submit a Matlab job and email the user when it
# is finished
# new to 2.3 - added option functionality
# - added option to suppress email
# - adjusted how errors are handled
### Setup options; if incorrect, notify of error and exit
email=yes
while getopts ':e' opt ; do
case $opt in
e) email=no ;;
\?) echo "Invalid option: -$OPTARG"
exit ;;
esac
done
# skip over the processed options
shift $((OPTIND-1))
### Test usage; if incorrect, output correct usage and exit
if [ "$#" -gt 2 -o "$#" -eq 0 ]; then
echo "********************************************************************"
echo "* Mathup version 2.3 *"
echo "********************************************************************"
echo -e "The 'mathup' script submits Matlab batch jobs using nohup. \n"
echo -e "usage: mathup [-e] file.m [output.log] \n"
echo -e "If only input_file.m is used, then input_file.mlog will be created. \n"
echo -e "Spaces in the filename or directory name may cause failure. \n"
exit
fi
# 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 -e "\n File does not exist, or option mispecified \n"
exit
fi
### Test file extension
if [[ $extension != m ]]; then
echo -e "\n Invalid input file, must be an m-file \n"
exit
fi
### Main file
# Direct output, conditional on number of arguments
if [[ "$#" -eq 1 ]]; then
output=$filestem.mlog
else
output=$2
fi
echo "mathup: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 /usr/local/bin/matlab -nodesktop -nodisplay -nosplash -nojvm < $1 > $output" >> $shell
echo "date >> $timer" >> $shell
if [[ $email == "yes" ]]; then
echo "mutt -s \"$1 finished\" -a $output nohup.out -- [email protected] < $timer" >> $shell
fi
nohup $shell &
# Nohup takes a split second longer than other commands
sleep 0.01s