Sponsored Content
Full Discussion: login audit bash script
Top Forums Shell Programming and Scripting login audit bash script Post 302599825 by agama on Saturday 18th of February 2012 06:25:44 PM
Old 02-18-2012
Quote:
Originally Posted by bashily
I have 2 questions:
1- How did you learn bash scripting so well?
Lots of practice. I've been writing code for a very long time now, and still learn something with nearly every post.

Quote:
2- I have to look at the whole /var/log/wtmp files. There are so many of them and I have to add them to one file but I can't Smilie

...

Then I have to add all the logged time of my users together and give a total as output. In your script you just used "last" command. which gives you only information from present machine not all other servers on the network.
correct me if I am wrong....
I see. I didn't grock that you needed to produce output based on all of them, and not just from the most recent.

I think you are on the right track. You might find this a bit easier to manage:

Code:
#!/usr/bin/env ksh

cd /tmp                     # safe place to work
tfile=/tmp/wtmp.$$          # temp file to uncompress into
big_file=/tmp/$USER.wtmp    #collect all output from wtmp into one file

ls /var/tmp/wtmp*bz2 | while read file    # for each wtmp file
do
    bunzip2 -dc $file >$tfile   # uncompress writing output to tmp file
    last -F -a -f $tfile        # run last on it
done >$big_file                 # save all output from last in one file
last -F -a >>$big_file          # append formatted output from current wtmp
rm $tfile                       # tmp file not needed

### parse your big file (/tmp/$USER.wtmp) here #####

# cleanup before exit
rm $big_file

This unzips each bzipped wtmp file directly to a temporary file, and then immediately runs last on it collecting all of the output in one file. A final last is executed which uses the current wtmp file and appends that output to the big file. You can then parse the big file as needed. You won't need a temporary directory because you don't have to copy the files.

Hope this helps.

Last edited by agama; 02-18-2012 at 07:31 PM.. Reason: added some comments
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash script for ssh login-

hi. I need a bash script which can login to an other mashin via SSH and then run some commands and then return the result to my mashine. I dont know where to begin, I think first I will need a ssh connection, dont know how to make it, then , do I need a ftp connection between the 2 mashins to... (5 Replies)
Discussion started by: big_pil
5 Replies

2. Shell Programming and Scripting

bash ssh login script

hello anyone have done ssh login script without "expect" (automatic login from host A / user b to Host B / user b without enter any passwords)? cheers (2 Replies)
Discussion started by: modcan
2 Replies

3. Shell Programming and Scripting

syntax error in audit script

Hi, When I run the following script #!/bin/sh email="rc@dll.com" subject="response times are more than a SECOND" rt=`tail audit.log | grep -i operationResponseTime | awk '{print $2}'` if then ### Mail the file to the mailbox mail -s $subject $email <<-end $rt ~.... (3 Replies)
Discussion started by: openspark
3 Replies

4. Shell Programming and Scripting

BASH ssh login

Ok, there's been a good number of posts about this, but here goes. I want a script to log in to a system via ssh without using keys. This will be used to log in to Cisco IOS devices. I have tried the following, but could not get it to work: SSH login expect shell script to supply username and... (1 Reply)
Discussion started by: mike909
1 Replies

5. Shell Programming and Scripting

Help with Unix bash shell script login

Hi, I am a complete Unix novice and need some help with creating a login shell script. I have created a file with user details i.e. PIN, name etc and require help in recalling the specified details from the file and being prompted for a password on login. Any help would be very much appreciated.... (0 Replies)
Discussion started by: tdsrogers
0 Replies

6. Shell Programming and Scripting

Bash Login tester Script help!

Hello, first of all, I am a pretty experience c++ programmer, but have never really bothered learning bash scripting at all, so I know conceptually things that can be done in c++, but I'm not too sure about bash. I'm trying to learn Bash, and wanted to start out with a practical application. So I... (1 Reply)
Discussion started by: RSPdev
1 Replies

7. AIX

When AIX audit start, How to set the /audit/stream.out file size ?

Dear All When I start the AIX(6100-06)audit subsystem. the log will save in /audit/stream.out (or /audit/trail), but in default when /audit/stream.out to grow up to 150MB. It will replace the original /audit/stream.out (or /audit/trail). Then the /audit/stream.out become empty and... (2 Replies)
Discussion started by: nnnnnnine
2 Replies

8. UNIX for Dummies Questions & Answers

Login PID in sh/bash different

In bourne shell the PID generated for the command "ps" matches my login id PID in the command "who -Hu" but in bash/linux the PID generated with the same commands are different . Why so? (2 Replies)
Discussion started by: asd78in
2 Replies

9. Shell Programming and Scripting

Automate OTPW login to ssh via bash script

Hello everyone. I'm a Linux novice trying out a lot of bash scripting lately, as it is so very addictive. Lately I have been setting up one of my boxes remotely and have been hardening it as much as possible. Please allow me to explain the scenario, as it does tend to become a little... (1 Reply)
Discussion started by: instro
1 Replies

10. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies
OPENVT(1)							     Linux 1.x								 OPENVT(1)

NAME
openvt - start a program on a new virtual terminal (VT). SYNOPSIS
openvt [-c vtnumber] [-s] [-u] [-l] [-v] [--] command command_options DESCRIPTION
openvt will find the first available VT, and run on it the given command with the given command options, standard input, output and error are directed to that terminal. The current search path ($PATH) is used to find the requested command. If no command is specified then the environment variable $SHELL is used. OPTIONS -c vtnumber Use the given VT number and not the first available. Note you must have write access to the supplied VT for this to work. -e Directly execute the given command, without forking. This option is meant for use in /etc/inittab. -s Switch to the new VT when starting the command. The VT of the new command will be made the new current VT. -u Figure out the owner of the current VT, and run login as that user. Suitable to be called by init. Shouldn't be used with -c or -l. -l Make the command a login shell. A - is prepended to the name of the command to be executed. -v Be a bit more verbose. -w wait for command to complete. If -w and -s are used together then openvt will switch back to the controlling terminal when the com- mand completes. -- end of options to openvt. NOTE
If openvt is compiled with a POSIX (GNU) getopt() and you wish to set options to the command to be run, then you must supply the end of options -- flag before the command. EXAMPLES
openvt can be used to start a shell on the next free VT, by using the command: openvt bash To start the shell as a login shell, use: openvt -l bash To get a long listing you must supply the -- separator: openvt -- ls -l HISTORY
Earlier, openvt was called open. It was written by Jon Tombs <jon@gtex02.us.es or jon@robots.ox.ac.uk>. The -w idea is from "sam". SEE ALSO
chvt(1), doshell(8), login(1) 19 Jul 1996 V1.4 OPENVT(1)
All times are GMT -4. The time now is 11:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy