- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Print from datestamp marker in file to end of ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 07:40 AM
11-09-2005 07:40 AM
For SOX reporting, I then want to email the contents of their HISTFILE from the *last* unique datestamp though the end of the file (and which point I write the datestamp again in prep for the next run in 15 days).
(We want to keep the HISTFILE intact up to its stated size, so I never want to permanently remove data that's already been emailed).
I have to imagine this is done with awk or sed, but I haven't found an example of this yet.
Any ideas?
Scott
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 08:49 AM
11-09-2005 08:49 AM
Re: Print from datestamp marker in file to end of file
#grab the line number of the last datestamp
LN=`nl HISTFILE |grep "#@!#@!#@!#@!" |tail -1 |awk '{print $1}'`
#email all lines from the last datestamp onward
tail -n +$LN HISTFILE |mailx -s "SOX HISTFILE Report" sysadmin@bigcompany.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 08:59 AM
11-09-2005 08:59 AM
Re: Print from datestamp marker in file to end of file
You could do something like:
# cat myextract
#!/usr/bin/perl -w
my $last =0;
die "Usage: $0 file\n" unless @ARGV;
open(FH, "<", "$ARGV[0]") or die "Can't open $!\n";
while (
seek(FH,0,0);
$. = 0;
do (
print while (
1;
#
Run as ./myextract ${HOME}/.sh_history
Modify the matching expression in the script if you need to do so. The output is the everything after the last occurance of the marker pattern.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 09:14 AM
11-09-2005 09:14 AM
Re: Print from datestamp marker in file to end of file
I get this when I run the perl script:
./myextract .xxxxx_history
Null filename used at ./myextract line 8,
(.xxxxx_history is quite large).
Here is the script (in vi with :set nu on); only the first line was changed:
1 #!/opt/perl/bin/perl
2 my $last =0;
3 die "Usage: $0 file\n" unless @ARGV;
4 open(FH, "<", "$ARGV[0]") or die "Can't open $!\n";
5 while (
6 seek(FH,0,0);
7 $. = 0;
8 do (
9 print while (
10 1;
11 #
Since I don't know perl at all, I'm at a loss.
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 09:16 AM
11-09-2005 09:16 AM
Re: Print from datestamp marker in file to end of file
I'm not getting any output. I notice when I run the nl command against the HISTFILE, I don't get all the output I woudl expect:
nl .xxxxx_history|tail
51631 stm
51632 51633 51634
51635 cd /scripts/src
51636 51637 51638 51639
51640 cd /scripts/src
51641 51642 51643 51644 51645 51646 51647 51648 51649 51650 51651 51652 51653 51654 51655 51656 51657 51658 51659 51660
51661 cd /scripts/lvm
51662 51663 51664 51665 51666 51667 51668 51669 51670 51671
The numbered lines without commands I believe should have a command next to them, but I don't know why.
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 09:20 AM
11-09-2005 09:20 AM
Re: Print from datestamp marker in file to end of file
This will create multiple files of the form-
xx00 xx01 xx02 ...
for each grouping of text that begins with #@#@#.
Then the last file in the sequence would be the text you want.
Here is a small script-
cd /tmp
mkdir roothist
cd roothist
n=`csplit /root/HISTFILE '/^#@#/' '{*}'| wc -l`
(( n = n - 1 ))
set -A a `ls -1`
cat ${a[$n]} >/tmp/HISTSNAP
n is set to the number of xx files created. We substract one since shell arrays are zero based.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 09:20 AM
11-09-2005 09:20 AM
Re: Print from datestamp marker in file to end of file
All the nl command does is get the point in the file from which to tail the output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 09:23 AM
11-09-2005 09:23 AM
SolutionMyHistFile=/where/ever/my/file/is/histfile
LastStampLine=`grep -n"${MyPattern}" "${MyHistFile}" | tail -1 | cut -d: -f1`
cat ${MyHistFile}|sed -e "1,${LastStampLine}d"|sendmail -v myemail@mycompany.com
I hope the above commands will work for you.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 09:36 AM
11-09-2005 09:36 AM
Re: Print from datestamp marker in file to end of file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 09:40 AM
11-09-2005 09:40 AM
Re: Print from datestamp marker in file to end of file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 09:43 AM
11-09-2005 09:43 AM
Re: Print from datestamp marker in file to end of file
I think that's going to do it.
I do need to simplify my datestamp. I think one or more of the characters #@! is causing trouble in the various solutions.
I will pick this up tomorrow and assign points!
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 09:49 AM
11-09-2005 09:49 AM
Re: Print from datestamp marker in file to end of file
What do you make of the cr/lf's in the HISTFILE? Why does that affect the nl output?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 01:42 PM
11-09-2005 01:42 PM
Re: Print from datestamp marker in file to end of file
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2005 11:58 PM
11-09-2005 11:58 PM
Re: Print from datestamp marker in file to end of file
this should work (I tested it on a plan ascii file and it's ok)
WrkFil=your_file
sed -n ''$(awk '/your_pattern/{N=NR}; END {print N+1}' $WrkFil)',$p' $WrkFil|mailx your_email_Address
the $(awk '/your_pattern/{N=NR}; END {print N+1}' $WrkFil) code, give you the last line in the file (+1) where your pattern is located
sed prints from the line to the end
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2005 02:44 AM
11-10-2005 02:44 AM
Re: Print from datestamp marker in file to end of file
No matter what I try, I keep getting "out of range" error messages.
A grep finds the string, but the csplit fails:
csplit /root/.xxxxx_history '/############ Sarbanes Oxley datestamp/' '{*}'
/############ Sarbanes Oxley datestamp/ - out of range
(I have simplified the timestamp to get rid of '@').
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2005 05:08 AM
11-10-2005 05:08 AM
Re: Print from datestamp marker in file to end of file
out of range means that the given argument did not reference a line between the current position and the end of the file. This warning also occurs if the file is exhausted before the repeat count is.
Which sounds like your timestamps as you supplied didn't match anything in the file.
It is a complex pattern. But you only have to match a portion, for instance-
/SOX datestamp/
might be sufficient...
Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2005 05:36 AM
11-10-2005 05:36 AM
Re: Print from datestamp marker in file to end of file
That's the strange part. This works:
grep Sarbanes /root/.xxxxx_history
############ Sarbanes Oxley datestamp Thu Nov 10 09:27:37 CST 2005 ############
############ Sarbanes Oxley datestamp Thu Nov 10 09:27:37 CST 2005 ############
etc, etc
But this does not:
csplit /root/.xxxxx_history '/Sarbanes/' '{*}'
/Sarbanes/ - out of range
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2005 06:39 AM
11-10-2005 06:39 AM
Re: Print from datestamp marker in file to end of file
It looks like this will work as well.
One part I forgot to mention is the timestamp could have rolled off of the HISTFILE (if there was a lot of command activity). So any solution I implement needs to take that into account.
Thanks to everyone for all the great ideas! I would never have come up with these.
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2005 11:05 AM
11-11-2005 11:05 AM
Re: Print from datestamp marker in file to end of file
2 00 * * * /var/adm/HistFileCopier.sh
where HistFileCopier.sh is something like this
userlist="rootusr1 rootusr2 rootusrN"
storageLOCATION=/var/adm/histSTORE
timestamp=`date +%Y%m%d%H%M`
for user in ${userlist}
do
strings ~${user}/.sh_history > ${storageLOCATION}/${user}.file.${timestamp}
done
then you can run your email reports against these files instead of the actual history files. As these will be cumulative, you need to develop an intelligence to make a line by line comparison between the current version and the previous version in order not to duplicate the entries.
As Bill Hassell stated, messing with .sh_history file in any way, shape or form, will render the contents useless. So, you need to devise a method to date and timestamp those. I must not have read your question in detail in my first answer before putting my response.
Also, another point, if you are this much concerned with what your root users did fro sox audits, I belive you already know that what you are doing is not sufficient to monitor your root users effectively since by granting them root access rights, you are giving them the keys to the mint. Once they gain root access whatever monitoring mechanism you instate locally on this server, cen be circumvented untraceably. Since these Sarbanes Oxymoron audits are that much of importance to you, I presume your organizations financial reporting is at utmost level, which in turn makes you eligible to spend some money on this end. If this is the case, go to
http://www.symark.com
and read about their product powebroker and its capabilities for reporting and root power delegation. That would be my suggestion to end your woes rather than developing homebrew sherlock applications.
HTH
UNIX because I majored in cryptology...