-
Notifications
You must be signed in to change notification settings - Fork 18
/
sinline
executable file
·87 lines (70 loc) · 2.04 KB
/
sinline
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
87
#!/bin/bash
set -e
print_usage () {
cat << EOM
Usage: $0 -n nodename -c command [-s sbatch_args]
Run a command and print the output to stout/stderr
Arguments:
-n nodename
The name of the node to run the command on
-c command
The command to run wrapped as a string (sim to -c
argument submitted to python)
-s sbatch_args
Arguments to supply to sbatch wrapped as a string
-k
Keep logs ./sbatch_std{out,err}.log and script /tmp/bash_script.sh
i.e. don't clean up (useful for debugging)
Example call:
$ sinline -n charles01 -c 'echo "It'\''s so convenient!"' -s '--time=00:01:00 -p Interactive'
submitting batch job 123456
It's so convenient!
$ # Return space used on all noninteractive charles scratch disks
$ for ii in {02..19}; do echo --------; echo charles$ii; sinline -n charles$ii -c 'du -sh /disk/scratch/*' 2>/dev/null | sort -rh ; done
EOM
}
node=''
cmd=''
sbatch_args=''
cleanup=1
# Parse args
while getopts 'n:s:c:k' flag; do
case "${flag}" in
n) node="${OPTARG}" ;;
s) sbatch_args="${OPTARG}" ;;
c) cmd="${OPTARG}" ;;
k) cleanup=0 ;;
*) print_usage
exit ;;
esac
done
# Check a node is supplied
if [ -z "${node}" ]; then
echo "You must supply a node to run the command on"
print_usage
exit 1
fi
# Check a command supplied
if [ -z "${cmd}" ]; then
echo "You must supply a command to run"
print_usage
exit 1
fi
# Add default sbatch args if not specified
if [ -z "${sbatch_args}" ]; then
# On some clusters e.g. cdtcluster, time arg is compulsory for job to run
sbatch_args="--time=00:30:00"
fi
echo '#!/bin/bash' > /tmp/bash_script.sh
echo '#SBATCH -o sbatch_stdout.log' >> /tmp/bash_script.sh
echo '#SBATCH -e sbatch_stderr.log' >> /tmp/bash_script.sh
echo "${cmd}" >> /tmp/bash_script.sh
sbatch --wait ${sbatch_args} -w ${node} /tmp/bash_script.sh
wait
cat sbatch_stdout.log >&1
cat sbatch_stderr.log >&2
# Clean up
if [ "${cleanup}" -eq "1" ]; then
rm sbatch_std{out,err}.log
rm /tmp/bash_script.sh
fi