-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRhup
executable file
·73 lines (59 loc) · 2.06 KB
/
Rhup
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
#!/bin/sh
# Rhup will prepare and submit an R job and email the user when it
# is finished
# Test usage; if incorrect, output correct usage
if [ "$#" -ne 1 ]; then
echo "********************************************************************"
echo "* Rhup version 2.0 *"
echo "********************************************************************"
echo "The 'Rhup' script submits R batch jobs using nohup."
echo ""
echo "Usage is:"
echo " Rhup <r_file.R>"
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.`
extension=`echo "$extension" | awk '{print tolower($0)}'`
# Test if file exist
if [[ ! -r $1 ]]; then
echo ""
echo "File does not exist"
echo ""
elif [[ $extension != r ]]; then
echo ""
echo "Invalid input file, must be an R-file"
echo ""
else
# Direct output
output=$filestem.Rout
echo "R: 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 R CMD BATCH $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