-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.sh
executable file
·69 lines (56 loc) · 1.29 KB
/
connect.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
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/bash
# Connect to a database, if more than one match a menu is shown to select connection
# connect.sh database
export passfile=./pass.sec
trap ctrl_c INT
function ctrl_c() {
chtitle "Cygwin"
exit 1
}
if [ $# -ne 1 ]; then
echo "Usage: connect.sh db"
exit 1
fi
findtns(){
awk -F"[ =]" '/DESCRIPTION/ { print X }{ X=$1 }' $tnsfile | grep -i $1;
}
chtitle()
{
cmd /c RenameTab "$1"
}
connect()
{
echo "Connecting to $1"
$sqlclexec "$USER/$PASS@$1"
chtitle "Cygwin"
}
getpass()
{
if [ -v $PASS ]; then
PASS=$(openssl enc -aes-256-cbc -d -in $passfile)
if [ $? -ne 0 ]; then
echo "Unable to decrypt password"
exit 1
fi
fi
}
connections=$(findtns $1)
if [ -z $(echo "$connections" | head -1) ];
then
echo "No Databases found containing $1."
exit 1
fi
if [ $(echo -e "$connections" | wc -l) -gt 1 ]
then
echo "Select database:"
IFS=$'\n'
select conn in $connections
do
break
done
else
conn=$connections
fi
getpass
chtitle $conn
connect $conn