ROOT-OTHER CONDITIONS
### time_check.sh
convert_time_seconds() {
#!/bin/bash
rm -Rf /tmp/timechecker.log
rm -Rf /tmp/time_of_logins.log
rm -Rf /tmp/time_to_seconds.log
cat /tmp/LOGIN_FAILED_ROOT.log | awk '{print $7}' >> /tmp/time_of_logins.log
cat /tmp/time_of_logins.log | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }' > /tmp/time_to_seconds.log
cat /tmp/time_to_seconds.log
times_count=`cat /tmp/time_to_seconds.log | wc -l`
echo " "
echo "-----------------------------------------------------------------"
echo "Total Number of Failed login attempts by Root User : $times_count"
echo "-----------------------------------------------------------------"
echo " "
}
convert_time_seconds
#### Second Script -----------Creating Variables equal to the count of inputs in seconds---------------------------------
### create_variables.sh
create_variables() {
#!/bin/bash
rm -Rf /tmp/variables.log
in_seconds=`wc -l < /tmp/time_to_seconds.log`
echo $in_seconds
for (( i=1; i<=${in_seconds}; i++ ));
do
echo num$i= >> /tmp/variables.log
done
}
==========================================
#!/bin/bash
assigning_variables() {
FILENAME="/tmp/variables.log"
while IFS= read -r line
do
sed -e 's/^/"${line}"/' /tmp/time_to_seconds.log > /tmp/time_to_seconds1.log
done < "$FILENAME"
cat /tmp/time_to_seconds1.log
}
assigning_variables
=====================================
assigning_variables() {
FILENAME="/tmp/time_to_seconds.log
while IFS= read -r line
do
/tmp/variables.log
done > "$FILENAME"
==================ARRAY
#!/bin/bash
FILENAME="/tmp/time_to_seconds.log"
arr=()
while IFS= read -r line; do
arr+=("$line")
done < "$FILENAME"
echo ${arr[0]}
echo ${arr[1]}
num2=$arr[0] + $arr[1]
echo num2 is $num2
for i in "${arr[@]}"
do
echo $1
done
================ARRAY
Add array elements - Shell Script
#sum of array shell script
arr=(10 20 30 40 50)
sum=0
for i in ${arr[@]}
do
sum=`expr $sum + $i`
done
echo $sum
array=( one two three )
for i in "${arr[@]}"
do
echo $i
done
Comments
Post a Comment