ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
small script that emails a login faliures report for all users of the system. i cant get the output to format nicely for excel. stdout displays ok, but when i open the csv i have the stdout spacing but its all in a single cell, making the csv look horrible. how do i write the output file so when it opens in excel the data is columnized?
Most likely you need to convert the CSV file in DOS format:
Code:
unix2dos $FILENAME
before attach it to the outgoing e-mail. The issue is that *nix systems use a line feed character as terminator, whereas windows uses a carriage return followed by line feed. A detailed explanation here: http://en.wikipedia.org/wiki/Newline
it should also create lines with "data1","data2" etc.
pam_tally2 output is two rows with 4 fields like this.
Login Failures Latest failure From
root 0 09/28/11 16:01:04 host.domain.com
so the awk prints every 2nd line as i dont need to repeat the 1st line in the report, etc. since pam_tally2 runs per "i" i changed the awk to be awk 'FNR ==2 {print}'
adding "," between fields works ok.
i changed it to be
pam_tally2 -u $i |awk 'FNR ==2 {print}' |awk '{ print $1, ",", $2, ",", $3, " ", $4, ",", $5}' >> $FILENAME
that works.
whats weird is, if user is uid=0 and gid=0 pam_tally2 reports the user as "root".
thnx
Last edited by Linux_Kidd; 09-29-2011 at 12:32 PM.
whats weird is, if user is uid=0 and gid=0 pam_tally2 reports the user as "root".
Why would this be weird? This is the standard on virtually all linux boxes that I am aware of (could be wrong but on the 20+ ditros I have tried this is the case).
Why would this be weird? This is the standard on virtually all linux boxes that I am aware of (could be wrong but on the 20+ ditros I have tried this is the case).
well, almost. notice the pam_tally2 output fields $3 and $4 belong together with the column heading of "Latest failure", so thats why i took the awk-newbie approach like i did.
as for pam_tally2, seems silly to think uid=0 gid=0 is the root account. sure, an account with 0 0 is a "root" but that doesnt mean it is "root". why wouldnt it just report the usernames as seen in /etc/passwd ???
no, what i am saying is, i have a user in passwd "johndoe" with uid=0 gid=0 and when i run "pam_tally2 -u johndoe" it returns "root" as the username in its output. i was expecting it to return the same username i passed it as a argument with "-u" switch, etc.
certainly "root" and "johndoe" are different accounts on the system.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.