nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

want a script keep backup of all users history.

This is a discussion on want a script keep backup of all users history. within the Shell scripting forums, part of the Development/Scripting category; Hi All, I want to write a script or may be a cron Job, which will make a backup of ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 22-08-2005, 05:23 PM
Member
User
 
Join Date: Jul 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
ricc
Default want a script keep backup of all users history.

Hi All,
I want to write a script or may be a cron Job, which will make a backup of the history file. For ex., an administrator may want to keep a backup of all the users history file silently, maybe everyday, just to keep a track of all the commands run by the user.

Thanks
rc
Reply With Quote
  #2 (permalink)  
Old 22-08-2005, 08:43 PM
rockdalinux's Avatar
Is that all you got?
User
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 708
Thanks: 15
Thanked 19 Times in 18 Posts
Rep Power: 10
rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light
Default

Well if your shell is /bin/bash then following should work:

Code:
BAK="/backup"
a=$(cut -d: -f6 /etc/passwd)
for i in $a
do
 [ -f $i/.bash_history ] && B="$B $i/.bash_history" || :
done
[! -d $BAK ] && mkdir -p $BAK || :
tar -zcvf $BAK/history.tar.gz $B
Test it and lemme know
__________________
Rocky Jr.
What's wrong? I hope I am not making you uncomfortable...

Never send a boy to do a mans job.
Reply With Quote
  #3 (permalink)  
Old 25-08-2005, 03:43 PM
Member
User
 
Join Date: Jul 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
ricc
Default

Thankx Rocky,
It works, but there was just a typo in the script.

Code:
[! -d $BAK ] && mkdir -p $BAK || :
I believe, would contain a space after "[" and before "!".

Code:
[ ! -d $BAK ] && mkdir -p $BAK || :
I am pointing this out just to let others know too and pls don't think otherwise.
I would like you to explain what does the " || : " do. I might also want you to include a date on the tar file generated, if we can. This way, we can have date wise history backups

Thanks again for your help.
rc
Reply With Quote
  #4 (permalink)  
Old 26-08-2005, 12:30 AM
rockdalinux's Avatar
Is that all you got?
User
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 708
Thanks: 15
Thanked 19 Times in 18 Posts
Rep Power: 10
rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light
Default

Opps

Thanks for making it correct
__________________
Rocky Jr.
What's wrong? I hope I am not making you uncomfortable...

Never send a boy to do a mans job.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
let users change password using perl script? james bond Getting started tutorials 9 24-05-2007 10:32 PM
need help in writing backup script vishaltitre Shell scripting 4 23-05-2007 10:07 PM
Script to add users to multiple servers. deepakhg Shell scripting 0 17-03-2007 03:02 AM
How to run script when users logouts tom Shell scripting 1 31-08-2005 11:42 PM
shell script for finding users not logged on for last 10 day ganes Shell scripting 4 06-07-2005 11:01 AM


All times are GMT +5.5. The time now is 06:04 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38