Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

Comment on Script to zip users cmd history log files
Select or Download Code
Re: Script to zip users cmd history log files
by choroba (Abbot) 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
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://951365]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-07-30 01:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls