<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: script formatting problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218699#M466352</link>
    <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; while this does keep the lines together, I still only get formatting on the first line returned, and hence my quandary from the start.&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;last -R|grep root|cut -c23-38,50-55|while read LINE&lt;BR /&gt;do&lt;BR /&gt;    print "\t\t${LINE}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Tue, 12 Jan 2010 20:29:00 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2010-01-12T20:29:00Z</dc:date>
    <item>
      <title>script formatting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218694#M466347</link>
      <description>O/S -&amp;gt; 11.11, PA-RISC&lt;BR /&gt;&lt;BR /&gt;I've been working on a script for our security folks that will email a report listing all accounts within a certain set that were logged in to directly (versus su'ing to them). &lt;BR /&gt;&lt;BR /&gt;If I run the command&lt;BR /&gt;last -R | grep &lt;ACCOUNT&gt; | cut -c23-38,50-55&lt;BR /&gt;&lt;BR /&gt;at the command line, I get this output:&lt;BR /&gt;&lt;BR /&gt;workstation_A.abc 12:09&lt;BR /&gt;workstation_B.def 11:28&lt;BR /&gt;workstation_C.xyz 09:19&lt;BR /&gt;&lt;BR /&gt;showing that the user I'm grepping for logged in from workstation A in the abc domain at 12:09, workstation B in the def domain at 11:28 and workstation C in the xyz domain at 09:19. That's all fine and good.&lt;BR /&gt;&lt;BR /&gt;If I then put this command in a for loop, like this (for the purposes of looping through the set of accounts I need to check):&lt;BR /&gt;&lt;BR /&gt;for i in `last -R | grep &lt;ACCOUNT&gt; | cut -c23-38,50-55`&lt;BR /&gt;do&lt;BR /&gt;print $i  (or echo, both results are the same)&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;I get this out put:&lt;BR /&gt;&lt;BR /&gt;workstation_A.abc &lt;BR /&gt;12:09&lt;BR /&gt;workstation_B.def&lt;BR /&gt;11:28&lt;BR /&gt;workstation_C.xyz &lt;BR /&gt;09:19&lt;BR /&gt;&lt;BR /&gt;Does anyone know why I'm getting different formatting from the same command? The only difference is that one is run at the command line straight out, the other is in a for loop (ksh).&lt;BR /&gt;&lt;BR /&gt;TIA, I'll give points where needed.&lt;BR /&gt;&lt;BR /&gt;-Gonzo&lt;BR /&gt;&lt;BR /&gt;&lt;/ACCOUNT&gt;&lt;/ACCOUNT&gt;</description>
      <pubDate>Tue, 12 Jan 2010 18:25:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218694#M466347</guid>
      <dc:creator>Kevin (Gonzo) Bushman</dc:creator>
      <dc:date>2010-01-12T18:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: script formatting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218695#M466348</link>
      <description>Because "i" takes on the value of "workstation_A.abc" and "12:09" on different iteration of the "for" loop.&lt;BR /&gt;&lt;BR /&gt;for i in "1 2 3 4 5"&lt;BR /&gt;do&lt;BR /&gt;print $i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;will print &lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;4&lt;BR /&gt;5&lt;BR /&gt;on separate lines. It does not matter that you have 3 lines, each line has two fields so you get 6 lines of output.&lt;BR /&gt;&lt;BR /&gt;You need to grep your user login names from a different source. Also I don't see why you are grepping your users from the same list that you want to print.&lt;BR /&gt;&lt;BR /&gt;Maybe something like&lt;BR /&gt;&lt;BR /&gt;for i in &lt;USERLIST&gt;&lt;BR /&gt;do&lt;BR /&gt;last -R | grep $i | cut -c23-38,50-55&lt;BR /&gt;done&lt;/USERLIST&gt;</description>
      <pubDate>Tue, 12 Jan 2010 18:43:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218695#M466348</guid>
      <dc:creator>TTr</dc:creator>
      <dc:date>2010-01-12T18:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: script formatting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218696#M466349</link>
      <description>TTr,&lt;BR /&gt;&lt;BR /&gt;I understand your point, and you are right. However, I looked at doing it the way you suggest. The problem is, if a given user has logged in multiple times, how do you format that output for the report I mentioned? That's why I was trying to handle it line by line, so I could format it for the report (for example, print "\t\t&lt;OUTPUT from="" last="" command=""&gt;"). If I try to format what you you suggest or what I was trying, only the FIRST entry gets formatted, not any following entries. So I'm back where I started. &lt;BR /&gt;&lt;BR /&gt;-Gonzo&lt;BR /&gt;&lt;/OUTPUT&gt;</description>
      <pubDate>Tue, 12 Jan 2010 19:04:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218696#M466349</guid>
      <dc:creator>Kevin (Gonzo) Bushman</dc:creator>
      <dc:date>2010-01-12T19:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: script formatting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218697#M466350</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;TTr is correct, which leads to quoting:&lt;BR /&gt;&lt;BR /&gt;for i in "$(last -R|grep &lt;ACCOUNT&gt;|cut -c23-38,50-55)"&lt;BR /&gt;do&lt;BR /&gt;    echo "${i}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;/ACCOUNT&gt;</description>
      <pubDate>Tue, 12 Jan 2010 19:25:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218697#M466350</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-01-12T19:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: script formatting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218698#M466351</link>
      <description>while this does keep the lines together, I still only get formatting on the first line returned, and hence my quandary from the start. That is,&lt;BR /&gt;&lt;BR /&gt;for i in "$(last -R | grep &lt;ACCT&gt; | cut -c23-38,50-55)"&lt;BR /&gt;do&lt;BR /&gt;  print "\t\t${i}" &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;(**I used print instead of echo to allow me to do some rudimentary formatting/spacing for the report.)&lt;BR /&gt;&lt;BR /&gt;yields:&lt;BR /&gt;&lt;BR /&gt;&lt;TAB&gt;&lt;TAB.WORKSTATION-A.ABC 09=""&gt;&lt;/TAB.WORKSTATION-A.ABC&gt;workstation-B.def  11:28&lt;BR /&gt;workstation-C.xyz  09:19&lt;BR /&gt;&lt;BR /&gt;What I need to be able to do for the report is something like this:&lt;BR /&gt;&lt;BR /&gt;                workstation-A.abc  12:09&lt;BR /&gt;                workstation-B.def  11:28&lt;BR /&gt;                workstation-C.xyz  09:19&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;-Gonzo&lt;BR /&gt;&lt;/TAB&gt;&lt;/ACCT&gt;</description>
      <pubDate>Tue, 12 Jan 2010 19:50:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218698#M466351</guid>
      <dc:creator>Kevin (Gonzo) Bushman</dc:creator>
      <dc:date>2010-01-12T19:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: script formatting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218699#M466352</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; while this does keep the lines together, I still only get formatting on the first line returned, and hence my quandary from the start.&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;last -R|grep root|cut -c23-38,50-55|while read LINE&lt;BR /&gt;do&lt;BR /&gt;    print "\t\t${LINE}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 12 Jan 2010 20:29:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218699#M466352</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-01-12T20:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: script formatting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218700#M466353</link>
      <description>&amp;gt;last -R | grep &lt;ACCOUNT&gt; | ...&lt;BR /&gt;&lt;BR /&gt;You can also provide the user names directly on the last(1) command line:&lt;BR /&gt;last -R &lt;ACCOUNT&gt;&lt;/ACCOUNT&gt;&lt;/ACCOUNT&gt;</description>
      <pubDate>Tue, 12 Jan 2010 21:47:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218700#M466353</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-01-12T21:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: script formatting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218701#M466354</link>
      <description>You can also provide the user names directly on the last(1) command line:&lt;BR /&gt;last -R &lt;ACCOUNT&gt;&lt;BR /&gt;&lt;BR /&gt;That's true, BUT, by doing the grep the way I had it eliminates the blank line and the "wtmp begins..." at the end of the report from the last command. (Hence the reason why I did the grep...)&lt;BR /&gt;&lt;BR /&gt;Also, JRF's solution looks to be the ticket. I tried it manually and it worked. All I have to do now is put that in a larger loop to run through the accounts I need to check...&lt;BR /&gt;&lt;BR /&gt;Actually, that is what I did manually. Tomorrow I will add this to my script and check to make sure it works. I've posted points where deserved and I will update tomorrow with the actual code I used in my script.&lt;BR /&gt;&lt;BR /&gt;Thanks to all for your replies! They just prove that sometimes you need another pair of eyes and another brain to look at a problem before you can see the solution!&lt;BR /&gt;&lt;BR /&gt;-Gonzo&lt;BR /&gt;&lt;/ACCOUNT&gt;</description>
      <pubDate>Tue, 12 Jan 2010 22:21:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218701#M466354</guid>
      <dc:creator>Kevin (Gonzo) Bushman</dc:creator>
      <dc:date>2010-01-12T22:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: script formatting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218702#M466355</link>
      <description>&amp;gt;by doing the grep the way I had it eliminates the blank line and the "wtmp begins..." at the end of the report from the last command.&lt;BR /&gt;&lt;BR /&gt;Performance wise, it is better to reduce the amount of data as close to the source as possible, otherwise you'll pass many megabytes in the pipe.  If you don't want to figure out how to remove the last two lines, you can still leave your grep there:&lt;BR /&gt;last -R &lt;ACCOUNT&gt; | grep -v -e "^$" -e "^WTMPS"&lt;BR /&gt;last -R &lt;ACCOUNT&gt; | grep &lt;ACCOUNT&gt;&lt;BR /&gt;&lt;BR /&gt;(Though you'll probably need to add a comment why are using the second grep. ;-)&lt;/ACCOUNT&gt;&lt;/ACCOUNT&gt;&lt;/ACCOUNT&gt;</description>
      <pubDate>Wed, 13 Jan 2010 04:29:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218702#M466355</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-01-13T04:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: script formatting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218703#M466356</link>
      <description>Dennis - Touche!&lt;BR /&gt;&lt;BR /&gt;Yeah, it only makes sense to run the last for the account in question to eliminate as much unneeded data as possible. Performance will be better that way. Then do a grep for the account again to also eliminate the blank line and the wtmp starts on line. That way you limit yourself to only the data you really are looking for.&lt;BR /&gt;&lt;BR /&gt;So, what I ended up doing was something like this:&lt;BR /&gt;&lt;BR /&gt;    last -R $ACCT | grep "$ACCT " | cut -c23-38,50-55 | while read LINE&lt;BR /&gt;    do&lt;BR /&gt;      print "\t\t   $LINE" &amp;gt;&amp;gt; $REPORT_FILE&lt;BR /&gt;    done&lt;BR /&gt;&lt;BR /&gt;This does keep the formatting on each and every line returned and prints it to the report file as it should so the data lines up in nice neat columns.&lt;BR /&gt;&lt;BR /&gt;Thanks all for your help. Security is much happier with the new report.&lt;BR /&gt;&lt;BR /&gt;Points given.&lt;BR /&gt;&lt;BR /&gt;-Gonzo</description>
      <pubDate>Wed, 13 Jan 2010 15:21:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218703#M466356</guid>
      <dc:creator>Kevin (Gonzo) Bushman</dc:creator>
      <dc:date>2010-01-13T15:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: script formatting problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218704#M466357</link>
      <description>Just closing the thread.&lt;BR /&gt;&lt;BR /&gt;See last comment for how the replies answered my question...&lt;BR /&gt;&lt;BR /&gt;Thanks all, yet again!&lt;BR /&gt;&lt;BR /&gt;-Gonzo&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Jan 2010 15:52:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-formatting-problem/m-p/5218704#M466357</guid>
      <dc:creator>Kevin (Gonzo) Bushman</dc:creator>
      <dc:date>2010-01-13T15:52:39Z</dc:date>
    </item>
  </channel>
</rss>

