Simple grep script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple grep script
# 1  
Old 09-28-2010
Simple grep script

I'm trying to write a simple script to identify every user who tried to “sudo” on the system. I have the first portion down to grep the log file

grep “sudo” /var/log/secure.

What I want to do is have the script identify the person just one time not every instance the user tried to sudo.


Thanks for your help.
# 2  
Old 09-28-2010
Give us a small sample of the log file -- /var/log/secure.
# 3  
Old 09-28-2010
Jim,

This is a sample of what is in the file. The only thing that changes is the sudo user, pwd and the command

sudo: pam_tally(sudo:setcred): unknown option: no_magic_root
sudo: usera : TTY=pts/2 ; PWD=/home/usera ; USER=root ; COMMAND=/bin/grep sudo /var/log/secure

Thanks.
# 4  
Old 09-28-2010
Code:
awk ' /^sudo:/ && !arr[$2]++ '  /var/log/secure

# 5  
Old 09-29-2010
Thanks for the suggestion - I'll give this a try when I get to work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

2. UNIX for Dummies Questions & Answers

Simple grep question

I hope someone can help me. I have a folder e.g. /opt/application Under that are many sub folders e.g. Folder1 Folder2 Folder3 Folder4 Folder5 Folder6 etc In some of these fodlers (not all of them) is a file called errors.log I need to run a grep that will start at... (3 Replies)
Discussion started by: gunnahafta
3 Replies

3. Shell Programming and Scripting

Help with simple RegEx on grep

Hello, I am trying to grep my log files for ORA errors, except ORA-00001. I have tried: grep 'ORA*!(-00001)' *.log but it is not working. Any help will be much appreciated. Thank you. (5 Replies)
Discussion started by: drbiloukos
5 Replies

4. Shell Programming and Scripting

Help with simple grep command

I am currently having a problem with displaying multiple occurences of a line using grep/sed combination. Let's say that I do grep "$anything" $file. When I do this it only displays a single line, but if I do grep -c "$anything" $file it says that there are 3 occurences of $anything, but how can... (15 Replies)
Discussion started by: puttster
15 Replies

5. Shell Programming and Scripting

Simple Shell Script to Grep

Hi guys, I have written this script, however the outcome is invalid. It contains grep search that is not needed: Script: #!/bin/bash #this is a test script FILES=$(ls /home/student/bin/dir1/*) GREPFUNC=$(grep -E -i "login|Successfully" ORProxyTC`date '+%m%d%Y'`*.txt/ ${FILES})... (14 Replies)
Discussion started by: DallasT
14 Replies

6. UNIX for Dummies Questions & Answers

Simple grep question

This should be so easy... I want to find all the apps in /Applications that start with the lower case i (e.g. iTunes.app, iSync.app, iCal.app) They should all have the .app extension. I've tried: ls /Applications |grep -o i*.app ls /Applications/i*.app Anyhow, I just want to see what apps... (2 Replies)
Discussion started by: glev2005
2 Replies

7. Shell Programming and Scripting

Problem with IF - CAT - GREP in simple shell script

Hi all, Here is my requirement I have to search 'ORA' word in out.log file,if it is present then i need to send that file (out.log) content to some mail id.If 'ORA' word is not in that file then i need to send 'load succesful' message to some mail id. The below the shell script is not... (5 Replies)
Discussion started by: mak_boop
5 Replies

8. Shell Programming and Scripting

simple grep is not working for me

Hi, On the log Netscape log, I need to grep for 500 error. I am doing that but I also get 1500 in that same log. cat access |grep "500" Results: "GET /css/RBR.css HTTP/1.1" 200 15000 304 - - - 399 639 523 164 0 This not what I need... Please advice. (4 Replies)
Discussion started by: samnyc
4 Replies

9. Shell Programming and Scripting

Simple grep Question

I tried searching for answers but didn't find any. When I grep a file results read 4.2.2.2 4.4.4.2 4.5.6.7 But I just want to select each result individually. For Example I want to be able to say variable1="first grep result" variable2="second grep result" variable3="third grep... (8 Replies)
Discussion started by: elbombillo
8 Replies

10. UNIX for Dummies Questions & Answers

simple grep question

I have seen this used several times but not really sure of what it actually does. I am confused with the second grep as the argument to the first. some commands | grep -v grep | some other commands Can anyone provide an explanation? Thanks, (5 Replies)
Discussion started by: google
5 Replies
Login or Register to Ask a Question