-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsif
executable file
·65 lines (60 loc) · 1.48 KB
/
csif
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
#!/bin/bash
# csif [-t] computer_num
# Connect to school computers
# Modes: control computer (default), 't'ransfer files, check 's'tatus
# of computers
# Relies on .ssh/config and sshmount to work properly
mydir="$( dirname -- "${BASH_SOURCE[0]}" )"
transfer_mode=0
no_mount=0
while getopts "stn" opt; do
case $opt in
t) # sftp
transfer_mode=1
shift 1
;;
s) # check status
open 'http://iceman.cs.ucdavis.edu/cgi-bin/nagios3/status.cgi?servicegroup=all&style=overview'
exit 0
;;
n) # without mount
no_mount=1
shift 1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
# Check remote status and get computer number
yn='n'
open 'http://iceman.cs.ucdavis.edu/cgi-bin/nagios3/status.cgi?servicegroup=all&style=overview'
while [[ "$yn" != 'y' ]]; do
read -r -p 'Checked remote status (y/n): ' yn
done
computer_num='n/a'
while ! [[ "$computer_num" =~ ^[0-9]+$ ]] ; do
read -r -p 'Enter computer to connect to: ' computer_num
done
echo "Connecting to computer $computer_num..."
# Connect
if [[ "$transfer_mode" == 1 ]]; then
sftp csif"$computer_num"
else
if [[ "$no_mount" == 0 ]]; then
mkdir "$HOME/remote/csif$computer_num"
sshmount csif"$computer_num"
# unmount and clean
read -r -p 'Unmount? ' yn
if [[ "$yn" == 'y' ]]; then
sshunmount csif"$computer_num"
rm -rf "$HOME/remote/csif$computer_num"
exit 0
else
echo "Exiting without unmounting..."
exit 0
fi
else
ssh csif"$computer_num"
fi
fi