Simple Script question


 
Thread Tools Search this Thread
Operating Systems AIX Simple Script question
# 1  
Old 07-13-2011
Simple Script question

I am trying to gather a report on service accounts. The report needs the account and the last time they changed there passwords date (Lastupdate). I have been doing this one by one and wondering if there is a simple for loop to gather all the information. your help is greatly appreciated.
# 2  
Old 07-13-2011
how you are doing manually ?

post the commands which you use to gather the report
# 3  
Old 07-13-2011
Code:
pwdadm -q Username | grep lastupdate

[once i have this i then convert using]

Code:
perl -le 'print scalar localtime shift'

# 4  
Old 07-14-2011
Quote:
Originally Posted by audis$
Code:
pwdadm -q Username | grep lastupdate

[once i have this i then convert using]

Code:
perl -le 'print scalar localtime shift'

In fact you do quite the same in a script. The following is a sketch which can perhaps be refined once we know a bit more about your environment, but it is a place to start. Save the following to a file (replace "<spc>" and "<tab>" with literal space/tab characters) and call it by "/path/to/script /path/to/inputfile":

Code:
#! /bin/ksh
# This script reads a list of usernames from a file and applies your command

typeset fIn="$1"
typeset chUser=""

cat "$fIn" | sed 's/#.*$//;s/^[<spc><tab>][<spc><tab>]*//;s/[<spc><tab>][<spc><tab>]*$//;/^$/d' |\
while read chUser ; do
     pwdadm -q "$chUser" | grep lastupdate | perl -le 'print scalar localtime shift'
done

exit 0

The input file should have one username in a line, comments and empty lines are possible. The sed-command just filters out white space and these comments, the rest is straight-forward.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 5  
Old 07-15-2011
Thank you for your reply.
I actually received some help from a co-worker. here is what i did-
1) created a file on each server called service accounts
2) added a list of accounts we wanted to report on in the service account file
3) coworker wrote a script
4) I ran the script from the NIM server.

Code:
for host in $(cat /home/user); do ssh $host 'hostname 1>&2; for user in $(cat /home/user/service_account); do sudo lsuser -a lastupdate $user | grep lastupdate; done'; done | perl -MPOSIX -e 'while (<STDIN>) { $_ =~ "^([^=]*)=(.*)\$"; print $1; print strftime(" %a %b %e %H:%M:%S %Y\n", localtime($2)); };'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple sed script question

Script newbie, so I'm sure I'm missing something obvious here, but how come this simple script does not work? #!/bin/bash ... (3 Replies)
Discussion started by: KidCactus
3 Replies

2. UNIX for Dummies Questions & Answers

Simple Script Question.

Hey guys im new to the whole linux and scripting community and am trying to get what (I think) should be a simple script to work. I understand pretty much everything up to line 20, which is where im getting the following errors: line 20: ' line 21: -le: command not found Any help or... (5 Replies)
Discussion started by: xburningphoenix
5 Replies

3. UNIX for Dummies Questions & Answers

Simple script question

How do you create a simple script that runs without the ./ ? (2 Replies)
Discussion started by: secno
2 Replies

4. Shell Programming and Scripting

Question about a simple Korn script

Hi to everybody! I want to write a simple script in ksh that decrypts and encrypts using the DES algorithm. There is no builtin function in UNIX : i have found only a function in openssl but i don't understand how to use it. The script must accept in input the plaitext and the DESKEY in... (2 Replies)
Discussion started by: kazikamuntu
2 Replies

5. Shell Programming and Scripting

dead simple bash script question

I need help writing a bash script that will simply prompt the user with a list of choices, then run an action based on the input. The action is running a wake-on-lan app called etherwake and passing a pre-defined mac address to the syntax. I have defined the three MAC addresses as: MAC1, MAC2,... (12 Replies)
Discussion started by: graysky
12 Replies

6. Shell Programming and Scripting

simple sh script question

folowing code is not working I am a newbie can u help me about it I need to match an array variable to a pattern which is like -rw-r--r-- if } =.r........ ] /* I tried to make every like to accept every thing that starts with any char that has secon char as r and accept any 8 chars after *\... (1 Reply)
Discussion started by: feline
1 Replies

7. Shell Programming and Scripting

Simple for script question

I haven't done any scripting for quite a while and was trying to remember how to do a script with a for loop that uses another command for input straight from the terminal, IE: for num in `cat somefile | awk <whatever>` do echo $num; echo blah; echo blahblah; done; Hopefully something quick... (1 Reply)
Discussion started by: Vryali
1 Replies

8. Shell Programming and Scripting

Simple Shell Script Question.... [java related]

Hey guys! This is my first post, as im new here :S I have a simple problem for a big program. We have a .sh to install it, but when I run the .sh in terminal like i should, It says the class is not found. I believe it has to do with the syntax, as the person who made it is not a linux pro. I... (3 Replies)
Discussion started by: Drags111
3 Replies

9. Shell Programming and Scripting

Simple script loop question

Hey all. Thanks in advance for any help you can give, hopefully this is an easy one. I want to create a loop to run a simple performance monitor like vmstat and record it to a file, but have very limited scripting skills (obviously). Starting with this... date >> /var/log/perfmon.log vmstat... (2 Replies)
Discussion started by: mattlock73
2 Replies

10. Shell Programming and Scripting

Simple awk script question

Hi, I'm a total beginner at awk and hope someone can advise what I have done wrong in the following script: I have a file which (to simplify things) may be something like this Fred Smith and Sue Brown Joe Jones and Jane Watts Sally Green and Jim O? Connor Freda O? Reiley and Pat O?... (2 Replies)
Discussion started by: Bab00shka
2 Replies
Login or Register to Ask a Question