Hello all,
so this is a script i did for an assignement,
- first option greets the user according to the time after fetching his name
- second options isn't implemented
- third check the performance according to how many users are using the system
- creates a log of names, time and ip of the user currently using the system.
problem is the script was working at some point, or so id like to believe.
after a few days i tried to run it, and i got syntax error on every option.
i tried looking over at it, but it seems right.
so im hoping someone would be able to figure out happened to it!!
echo Choose Number to select:
echo 1.Greet User
echo 2.Replace Patter
echo 3.Check Performance
echo 4.Log info
echo 5.Exit
read choice
user=$(whoami | cut -d" " -f1 )
name=$(grep $user /etc/passwd | cut -d: -f5)
while [ $choice -ne 5 ]
do
if [ $choice -eq 1 ]
then
time=$(date | cut -d" " -f5 | cut -d: -f1)
if [ $time -gt 00 -a $time -le 12 ]
then
echo Good Morning $name
elif [ $time -gt 12 -a $time -le 17 ]
then
echo Good Afternoon $name
elif [ $time -gt 17 -a $time -le 24 ]
then
echo Good Evening $name
fi
elif [ $choice -eq 2 ]
then
echo $choice
elif [ $choice -eq 3 ]
then
users=$(uptime | cut -d" " -f8)
if [ $users -ge 0 -a $users -lt 7 ]
then
echo System has high performance
elif [ $users -ge 7 -a $users -lt 12 ]
then
echo System has medium preformance
elif [ $users -gt 12 ]
then
echo System has low performance
fi
elif [ $choice -eq 4 ]
then
who > temp
lines=$(wc -l ./temp | cut -d" " -f1)
cnt=1
touch tmplog
touch logfile
while [ $cnt -le $lines ]
do
usertemp=$(head -$cnt ./temp | tail -1 | cut -d" " -f1)
nametemp=$(grep $usertemp /etc/passwd | cut -d: -f5)
datetemp=$(head -$cnt ./temp | tail -1 | cut -d" " -f13)
adrstemp=$(head -$cnt ./temp | tail -1 | cut -d" " -f14)
if [ "$usertemp" != "$user" ]
then
echo -n $nametemp >> tmplog
echo -n " " >> tmplog
echo -n $datetemp >> tmplog
echo -n " " >> tmplog
echo -n $adrstemp >> tmplog
echo "" >> tmplog
fi
timetemp=$(head -$cnt ./temp | tail -1 | cut -d" " -f1)
let cnt=$cnt+1
done
sort -db tmplog -o logfile
rm temp
rm tmplog
else
echo no such option
fi
echo Choose Number to select:
echo 1.Greet User
echo 2.Replace Patter
echo 3.Check Performance
echo 4.Log info
echo 5.Exit
read choice
done