I would like to write a bash script, that takes two parameters as input (day hostname) and outputs the username of all users that logged in on the day of the current month and from the address of hostname.
I have written this code until now:
#!/bin/bash
#parameter correction checking
if [ ! $# -eq 2 ]
then echo "You have input the wrong number of parameters!"
fi
#Current month checking
CurrentMonth=`date | cut -d' ' -f2`
#This will contain the abbreviation of the current month: e.g "Mar"
#$2 -> IP/hostname; $1 -> day (of the current month)
last | grep '$2' | grep '$CurrentMonth $1' | cut -d' ' -f1
#here the two greps will get the lines that check out our requirements, and the cut will return only the username
What did I do wrong?
The code runs just fine if I replace the CurrentMonth variable with Mar and the $2 with an actual IP address