- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell scripts for calculating the number of days b...
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
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
04-18-2001 07:10 PM
04-18-2001 07:10 PM
I am trying to write a script which calculates the difference between the two dates and gives it as the number of days say for Eg: between today 4/18/01 and 3/18/01 its 30 days.
My aim is to monitor the last login time of a user and compare it with the system date and in case its more than 60 days I want to send a alert saying user has been idle. My client runs a NIS environment and he doesnt havee trusted systems. I have tried writing the following script below, can you pl guide me and let me know if its the correct way?
Thnks in advance
Shiv
_______________________________________________
#! /bin/sh
OL=`TZ=PST+1440 date +%m%d`
TO=`date +%m%d`
LST=`last -1 karin | awk '{print $6}'`
MON=`last -1 karin | awk '{print $5}'`
case $MON in
Jan) MO=01;;
Feb) MO=02;;
Mar) MO=03;;
Apr) MO=04;;
May) MO=05;;
Jun) MO=06;;
Jul) MO=07;;
esac
CK=$MO$LST
echo Last Login Date $CK
if [ $OL -lt $MO ]
then
echo This user has not loged last 60 days;
echo This user has to be deleted ;
else
echo User logged within 60 days;
fi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2001 11:13 PM
04-18-2001 11:13 PM
Solutioninstead of really calculating the difference between the two dates, and relying on the fact that 'last' can supply the last login date,
I would go for another option:
- touch a file in their home dir each time they login (touch $HOME/.lastlogin in their .profile)
- you can check if this file is recent with find:
--- find $HOME -name '.lastlogin' -mtime +60
good luck,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 04:07 AM
04-19-2001 04:07 AM
Re: Shell scripts for calculating the number of days betn DATES
I think Thierry's approach is the most direct. I would only add two comments:
1. 'last' is an excellent choice. It will only work if you have maintain (first touch) '/var/adm/wtmp'. See the man pages for 'last'. Depending on the number of users and logins you might not want to keep upwards of 60-days of information this way.
2. Assuming a posix or ksh shell is being used, you could track the HISTFILE file (normally $HOME/.sh_history) as your reference point.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 04:23 AM
04-19-2001 04:23 AM
Re: Shell scripts for calculating the number of days betn DATES
Look for Al Langen post:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x57eff841489fd4118fef0090279cd0f9,00.html
/rcw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 02:16 PM
04-19-2001 02:16 PM
Re: Shell scripts for calculating the number of days betn DATES
#include
main(argc,argv)
int argc;
char ** argv;
{
time_t num_secs;
num_secs=time(NULL);
printf("%u",num_seecs);
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 02:56 PM
04-19-2001 02:56 PM
Re: Shell scripts for calculating the number of days betn DATES
You simply call the shell function
julian_day MM/DD/YYYY and it returns a number.
Call it with another date and subtract the two and ther you are.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 03:06 PM
04-19-2001 03:06 PM
Re: Shell scripts for calculating the number of days betn DATES
Retrieve the field by doing something like
mypr_passwdent=getprpwent();
days_between=(time(NULL)-(&mypr_passwdent->ufld.fd_slogin))/86400
printf("%d days since last login",days_between);
Note: this is code is meant as an example, man is your friend; this code is incomplete, but should give a C programmer enough to succesfully write a working utility.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 03:20 PM
04-19-2001 03:20 PM
Re: Shell scripts for calculating the number of days betn DATES
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2001 10:33 AM
04-20-2001 10:33 AM
Re: Shell scripts for calculating the number of days betn DATES
Thnks for the help,