How-To format output in CSV to match stdout?
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?
Code:
#!/bin/bash |
Most likely you need to convert the CSV file in DOS format:
Code:
unix2dos $FILENAME |
well, not quite
if data is not formatted in CSV then it won't be read into columns (CSV - comma separated values) so the structure of data should be: Code:
"Col 1 header","Col 2 header","Col 3 header" Code:
echo "Login Failures Latest failure From" >> $FILENAME so you should modify it and also what is the output of Code:
pam_tally2 -u $i |awk '0 ==NR % 2' >> $FILENAME good luck |
Quote:
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 |
Quote:
Also, no need to get so heavy handed with awk: Code:
pam_tally2 -u $i |awk 'FNR ==2 && $1 = $1' OFS="," |
Quote:
so i simplified some and went with awk 'FNR ==2 { print $1","$2","$3," "$4","$5}' >> $FILENAME 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 ??? thnx all for the help. |
Quote:
|
Quote:
certainly "root" and "johndoe" are different accounts on the system. |
All times are GMT -5. The time now is 09:32 AM. |