Hi!
For the school, i have an exercice and even the teacher have difficulties to resolve this.
i have to write a script and i m supposed to use echo, grep, cut, sort, uniq, sed and awk.
and i ll be looking like:
---------------------------------------------------------------------------------------------
Date of execution of execution of the script : ---------------
Stats of failed connection on ssh by users
--------------------------------------------------------------------------------------------
|User account | Nbres of Failures | Last date of failure |
--------------------------------------------------------------------------------------------
|user$1 | X | Day xx HH:MM:SS |
|user$2 | X | Day xx HH:MM:SS |
--------------------------------------------------------------------------------------------
By now , i have :
# cat /var/log/secure* | grep "Failed password" | grep -v "invalid" > tmp1
# awk '{print $9} tmp1 | sort | uniq -c
#cat tmp1 | grep "user$1" | sort | tail -1 | awk ' {print $1,$2,$3}'
#cat tmp1 | grep "user$2" | sort | tail -1 | awk ' {print $1,$2,$3}'
I'm really lost now,
Thanks for your help
Jules
Problem with awk and script!
Re: Problem with awk and script!
So in this set of commands the first cat is completely unnecessary since you can tell grep or awk or whatever to read the file directly instead of reading standard input. Second, there's no real reason to create a temporary file since you can just pipe the output from teh first set of commands into the awk/sort/uniq that follows.# cat /var/log/secure* | grep "Failed password" | grep -v "invalid" > tmp1
So your first set of commands cat /var/log/secure* | grep "Failed password" | grep -v "invalid" can be replaced with something like
awk '/Failed password/ { print $9" Day "$2" " $3 }' /var/log/secure | grep -v invalid | sort -r | uniq -c -w 8
My /var/log/secure doesn't contain a field with the Day of the week in it so if you need that (your description is unclear about what's needed) you're going to need to extract Month and day number then convert that to the DoW.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke
Re: Problem with awk and script!
If you really have to use all of the commands
Read the awk man page a couple of times at least. Then you need to do the following:
then it's a fairly pointless exercise in making life difficult. You only need AWK, it will do all that you want. I'm not about to do your homework for you, but basically the shell script is:i m supposed to use echo, grep, cut, sort, uniq, sed and awk
Code: Select all
#!/bin.sh
awk '
...
' /var/log/secure*
- Write section that matches with "Failed password". When it runs, ignore any "invalid" lines (hint: "next" is useful here). Next extract the information, format it and save in in an array indexed on the user. Also build up your running totals.
- Write an END section which prints out your first 6 lines. Then use asorti() to sort the array. Finally use a counter to take each array element in turn and print the formatted string you saved earlier.
Re: Problem with awk and script!
Thanks for your help TrevorH and MartinR!
I m sorry for my unclear description of my problem , and i m not looking for someone to do my homework but just want to understand how to build a script.
I ll try to manage something with your hints. And i agree with you , i think this is pointless!
Jules
I m sorry for my unclear description of my problem , and i m not looking for someone to do my homework but just want to understand how to build a script.
I ll try to manage something with your hints. And i agree with you , i think this is pointless!
Jules