- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell script to compare the date !!
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
05-04-2002 12:25 AM
05-04-2002 12:25 AM
I would like to write a script for tracking those users who were not logged in to the server for more than 3 months. By comparing the /bin/last output for /var/adm/wtmp file and password file, I obtained a list of username and timestamps for their login and logout time. Now the problem is how can I compare the date specified in /var/adm/wtmp file with the current date?? I couldn't find any useful command for this task.
Appreciated it if anyone can help solving this problem with sample codes and/or url links.
Many thanks,
Chris,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2002 01:09 AM
05-04-2002 01:09 AM
SolutionTry putting A. Clay Stephenson's caljd.sh script to good use, where possible:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x6e7a7d4cf554d611abdb0090277a778c,00.html
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2002 07:03 AM
05-04-2002 07:03 AM
Re: Shell script to compare the date !!
This is one of those cases where caljd.sh (or the newer caljd.pl) is probably not the best choice. My approach would be to use that really big number (the epoch seconds timestamp) just before the month.
#!/usr/bin/sh
FIN=/var/adm/wtmp
CMD=/usr/sbin/acct/fwtmp
STAT=1
if [ -r ${FIN} -a -x ${CMD} ]
then
${CMD} < ${FIN} | perl wtmpparse.pl
STAT=$?
fi
exit ${STAT}
The attached wtmpparse.pl script will then look at the timestamp and append something like '32.45 days' to each input line. If you look at the perl script, you will see a commented line that will instead output an integer '32 days' instead.
This should be very close to your needs. You may also need to play with the substr() offset to locate the timestamp within your platform's fwtmp output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2002 07:40 PM
05-04-2002 07:40 PM
Re: Shell script to compare the date !!
One another way I can think of is to check the home directory using -mtime option of find.
1. Get the user list from /etc/passwd
2. For each user, determine if any of the files in his/her home directory have been modified since the desired number of days. .last_login is one such file by default gets modified when the user logs in.
A primitive script is below. You can modify it to your requirements.
#!/usr/bin/ksh
if [ $# != 1 ]
then
echo "Usage: $0 days_of_inactivity"
exit 1
fi
STAMP=$1
cat /etc/passwd |
while read entry
do
LOGIN=`echo $entry |awk '{FS=":";print $1}'`
HOME=`echo $entry |awk '{FS=":";print $6}'`
SUCCESS=`find $HOME -mtime -$STAMP -print -quit | wc -l`
if [ $SUCCESS -eq 0 ]
then
echo "$LOGIN "
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2002 06:13 AM
05-05-2002 06:13 AM
Re: Shell script to compare the date !!
I created a script which calls Caljd.sh to calculate the julian day for me. Then I compare the current Julian day and the returned Julian days from the /var/adm/acct/sum/loginlog file (suppose a cron job will run the lastlogin command everyday to update the logiinlog file).
If the current Julian day - returned Julian day >= 90 days (i.e 3 months roughly), the particular username will be printed out in a report.
Cheers,
Chris,