Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Script to zip users cmd history log files

by hedkandi (Initiate)
on Feb 02, 2012 at 06:14 UTC ( #951365=perlquestion: print w/replies, xml ) Need Help??
hedkandi has asked for the wisdom of the Perl Monks concerning the following question:

I admit I am terrible with scripting, so when I was asked to store users' command history lines and zip them on monthly basis what I did was to create a file "user_history_Feb" with the following contents: Part A
[root@H99XXX bin]# more user_history_Feb cp -p /var/log/user_history/*history /var/log/user_history/old_logs/ gzip -9 /var/log/user_history/old_logs/*history cd /var/log/user_history/old_logs mv *gz /var/log/user_history/old_logs/02 [root@H99XXX bin]#
and a cronjob for it to run end of Feb: Part B
[root@H99 bin]# crontab -l | grep user_history_Feb 01 22 29 2 * /usr/local/bin/user_history_Feb [root@H99 bin]# uname -a Linux H99 2.6.18-274.17.1.el5 #1 SMP Wed Jan 4 22:45:44 EST 2012 x86_6 +4 x86_64 x86_64 GNU/Linux [root@H99 bin]#
I am using RHEL 5.7 I know my "script" is no script, and would be very thankful if someone could help me into scriptifying part A so I can adjust the cron

Replies are listed 'Best First'.
Re: Script to zip users cmd history log files
by Anonymous Monk on Feb 02, 2012 at 09:01 UTC

    Use username-hist-yyyy-mm, you'll thank me next year

Re: Script to zip users cmd history log files
by choroba (Chancellor) on Feb 02, 2012 at 08:54 UTC
    In which aspect is your question related to Perl?
      Hi there, never mind. I wanted to do a Perl Script of the commands I provided but had some help doing it in Bash script so that pretty much did the job.
      #!/bin/bash OLD_HIST_DIR="/var/log/user_history/old_logs" HIST_DIR="/var/log/user_history" MNTH_DEST_DIR="/var/log/user_history/old_logs/$(date +'%m')" # date +'%m' gives number corresponding to the current month in 01,02, +...11,12 fashion mkdir -p "${MNTH_DEST_DIR}" "${OLD_HIST_DIR}" # This will create the +directory if not present cp -p ${HIST_DIR}/*history ${OLD_HIST_DIR} gzip -9 ${OLD_HIST_DIR}/*history mv ${OLD_HIST_DIR}/*.gz ${MNTH_DEST_DIR}
      @admins you may close this thread

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://951365]
[1nickt]: heh, I hab\ve been. Trying to understand it.
[1nickt]: perl -e 'print 1.0' ... output '1'.
[Lady_Aleena]: You could quote it. <c>perl -e 'print "1.0"'>/c> returns 1.0
[Lady_Aleena]: perl -e 'my $var = "1.0"; print $var;' if it is in a variable also returns 1.0, though perl -e 'my $var = 1.0; print $var;' returns 1.
[1nickt]: In my case I can simply pass sprintf '%.1f', 1.0 (to Types::Standard:: Int), but what if you didn;t know the precision of the number you were working with? Seems I must be missing something. Oh well, my test list is complete, mooving on ...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2017-05-24 18:47 GMT
Find Nodes?
    Voting Booth?