- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Tracking sh_history
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
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
09-28-2004 01:19 PM
09-28-2004 01:19 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2004 09:45 PM
09-28-2004 09:45 PM
Re: Tracking sh_history
listusers so that,
we can append all system users history every day as,
# Use with root user
COMHISTFILE=/var/adm/syslog/histfile.log
COMHISTERR=/var/adm/syslog/histfile.err
for user in `listusers`; do
id $user >> $COMHISTFILE
echo $user >> $COMHISTFILE
date >> $COMHISTFILE
if [[ -f /home/$user/.sh_history ]]
then
cat /home/$user/.sh_history >> $COMHISTFILE
else
echo "History file /home/$user/.sh_history not found" >> $COMHISTERR
fi
done
Simulate this with cron job or execute on command line on particular time there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2004 10:29 PM
09-28-2004 10:29 PM
Re: Tracking sh_history
#!/usr/bin/sh
# permission to run - super user
# Command history and error file
COMHISTFILE=/var/adm/history.log
COMERRFILE=/var/adm/history.err
# Log appending
for user `listusers`; do
echo "==============================" >> $COMHISTFILE
echo "USER: $user" >> $COMHISTFILE
echo "DATE: $(date)" >> $COMHISTFILE
echo "ID: $(id $user)" >> $COMHISTFILE
echo "==============================" >> $COMHISTFILE
hist=$(su - $user -c "echo $HISTFILE")
if [[ -f $hist ]]
then
cat $hist >> $COMHISTFILE
else
echo "ERROR: $user has no history file there" $COMERRFILE
fi
done
IF you want to change the location of common history file some where then be care that normal users can not access it.
/var/adm/ directory will be with access to root user only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2004 10:27 AM
09-29-2004 10:27 AM
Re: Tracking sh_history
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2004 10:45 AM
09-29-2004 10:45 AM
SolutionYou can try something like this
Create a script that captures these log files
# vi /usr/local/bin/sh_hist_cap.sh
HIST_ARCH=/var/adm/logs/hist.archive
logins | awk '{print $1}' | while read USER
do
( echo "====================================================="
echo " Login : $USER Date: $(date)"
echo "====================================================="
cat ~${USER}/.sh_history
echo "====================================================="
) >> $HIST_ARCH
> ~${USER}/.sh_history
done
#
# mkdir /var/adm/logs
# chmod +x /usr/local/bin/sh_hist_cap.sh
# crontab -e
45 23 * * * /usr/local/bin/sh_hist_cap.sh
#
Schedule this job to run everyday at say 11:45 PM, for example.
- Sundar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2004 12:08 PM
09-29-2004 12:08 PM
Re: Tracking sh_history
Thank you for the script. It is exactly what I was looking for!!!
How would be the best way to eliminate users who do not have a .sh_history file? Thanks again.
Bobby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2004 12:19 PM
09-29-2004 12:19 PM
Re: Tracking sh_history
1) This will completely skip the logins without the history file
# vi /usr/local/bin/sh_hist_cap.sh
HIST_ARCH=/var/adm/logs/hist.archive
logins | awk '{print $1}' | while read USER
do
[[ ! -f ~$USER/.sh_history ]] && continue
( echo "====================================================="
echo " Login : $USER Date: $(date)"
echo "====================================================="
cat ~${USER}/.sh_history
echo "====================================================="
) >> $HIST_ARCH
> ~${USER}/.sh_history
done
#
2) This will log a message in the hist.archive for the logins without the history file.
# vi /usr/local/bin/sh_hist_cap.sh
HIST_ARCH=/var/adm/logs/hist.archive
logins | awk '{print $1}' | while read USER
do
( echo "====================================================="
echo " Login : $USER Date: $(date)"
echo "====================================================="
if [ -f ~${USER}/.sh_history ]
then
cat ~${USER}/.sh_history
else
echo "\t\tNo .sh_history for the user !!"
fi
echo "====================================================="
) >> $HIST_ARCH
> ~${USER}/.sh_history
done
#
- Sundar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2004 03:00 PM
09-29-2004 03:00 PM