-
Notifications
You must be signed in to change notification settings - Fork 0
/
customcase.sh
executable file
·74 lines (61 loc) · 1.51 KB
/
customcase.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
70
71
72
73
74
#!/bin/bash
#Manolis Kartsonakis
#see git/gitlab for commits
#Check if argument 1 is empty
if [ "$1" == "" ]; then
echo -e "\nusage is $0 hostname\n"
exit 1
fi
custfolder="./"
sysname=$1
username=YOUR_USERNAME
password=YOUR_PASSWORD
date=`/bin/date +"%Y-%m-%d"`
tmpdir=/tmp/custom-shows
commands=$custfolder/commands.list
logfile=$tmpdir/$sysname.log
lockfile=$tmpdir/$sysname.lock
new=0
maxversions=40
worked=0
function lecho {
isodt=`/bin/date +"%Y-%m-%dT%H:%M:%S"`
echo "$sysname $isodt $1" | tee -a $logfile
}
#Create a temp folder
if ! [ -d $tmpdir ]; then
/bin/mkdir $tmpdir
/bin/chmod 777 $tmpdir
fi
#Don't run again if running
if [ -f $lockfile ]; then
lecho "Lock file exists, aborting."
exit 1
else
trap "/bin/rm -f $lockfile; exit" INT TERM EXIT
/bin/date +"%Y-%m-%dT%M:%H:%S" > $lockfile
fi
#Clean old temp logfile and output file if any
if [ -f $logfile ]; then
/bin/rm -f $logfile
/bin/rm -f $tmpdir/$sysname*
fi
#Set Internal Field Separator in order to read per line and not per word
OLDIFS=$IFS
IFS=$'\n'
for command in `cat $commands`;do
output=iosxr_`echo $command | sed 's/ /_/g'`
type=cisco
#setting/create the output directory:
directory="$custfolder/$type/$sysname"
if [ ! -d $directory ]; then
mkdir $directory
new=1
fi
# ****** RUN THE SCRIPT *******
$custfolder/cisco_show.exp $username $password $1 $sysname $command > $directory/$output 2>&1 && echo "Done with $sysname"
done
IFS=$OLDIFS
/bin/rm -f $lockfile
#
trap - INT TERM EXIT