-
Notifications
You must be signed in to change notification settings - Fork 0
/
telnetLog.sh
executable file
·63 lines (47 loc) · 1.34 KB
/
telnetLog.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
#!/bin/bash
#check number of args
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "Illegal number of parameters"
exit 2
fi
#set current date and date with time
currDateAndTime=`date +"%Y-%m-%d_%T"`
currDate=`date +"%Y-%m-%d"`
#create dir for logs
mkdir -p "${currDate}"
if [ "$#" -eq 2 ]; then #check existence of second arg and comment
if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then #check if first arg is ip
#set ip and comment variable
ip=$1
comment=$2
elif [[ $2 =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then #check if second arg is ip
#set ip and comment variable
ip=$2
comment=$1
else
#if ip isnt set exit
echo "ip is not set"
exit 2
fi
#create log file name variable
logFileName="${currDate}//${comment}_${ip}_$currDateAndTime".log
#connect to host and start log
script -c "telnet ${ip}" ${logFileName}
elif [ "$#" -eq 1 ]; then #if comment isnt set then check existence of first arg
if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then #check if first arg is ip
#set ip
ip=$1
else
#if ip isnt set exit
echo "ip is not set"
exit 2
fi
#create log file name variable
logFileName="${currDate}//${ip}_${currDateAndTime}".log
#connect to host and start log
script -c "telnet ${ip}" ${logFileName}
else
#i dont know why im writing this
echo "something strange happen"
exit 2
fi