-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo-run.sh
executable file
·56 lines (49 loc) · 1.33 KB
/
go-run.sh
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
#!/bin/bash
function showHelp() {
echo "Available options :"
echo "-f | --file Go file to run"
echo "-p | --port Port to kill"
echo "-o | --output Output file for logging"
echo "-h | --help Show help"
}
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
-f | --file )
shift; file=$1
;;
-p | --port )
shift; port=$1
;;
-o | --output )
shift; output=$1
;;
-h | --help )
showHelp
exit
;;
* )
echo "Invalid option $1"
showHelp
exit 1
;;
esac; shift; done
if [[ "$1" == '--' ]]; then shift; fi
if [[ -z $file ]]; then
echo "File can't be empty!"
showHelp
exit
fi
if [[ ! -f $file ]]; then
echo "$file doesn't exist"
exit
fi
if [[ -z $port ]]; then
echo "Port can't be empty!"
showHelp
exit
fi
if [[ -z $output ]]; then
output=output.log
fi
PID="$(sudo lsof -i :$port | awk '{print $2}' | tail -n 1)"
kill "$PID"
./$file | awk -v time="$(TZ='Asia/Jakarta' date +"[%d-%m-%Y %H:%M:%S]")" '{ print time, $0; fflush(); }' >> "$(dirname $0)/$output" &