Operating System - HP-UX
1752809 Members
6158 Online
108789 Solutions
New Discussion

Restricting user to login after there shift

 
Dennis Handly
Acclaimed Contributor

Re: Restricting user to login after their shift

WDAY=$(date "+%w") # 0-Sunday, 6=Saturday

HOUR=$(date "+%H")

 

Pedantic mode on:

Decades ago starting my first programming job, one of the first things I learned from an old timer is that you never want to ask for the time & date with two calls.  I.e. the first could be right before midnight.

You could also ask for WDAY again (especially if you have a broken OS that doesn't give you both at the same time) and compare, assuming the process didn't hang for 24 hours.  ;-)

James R. Ferguson
Acclaimed Contributor

Re: Restricting user to login after their shift


@Dennis Handly wrote:

WDAY=$(date "+%w") # 0-Sunday, 6=Saturday

HOUR=$(date "+%H")

 

Pedantic mode on:

Decades ago starting my first programming job, one of the first things I learned from an old timer is that you never want to ask for the time & date with two calls.  I.e. the first could be right before midnight.


Well, that's not so pedanitc :-)  It's the same consideration we give to avoiding race conditions.

 

I would do better if I had done:

 

DATETIME=$(date "+%w":%H)
WDAY=$(echo ${DATETIME}|cut -d":" -f1)
HOUR=$(echo ${DATETIME}|cut -d":" -f2)

 Regards!

 

...JRF...

 

Re: Restricting user to login after their shift

Hi,

 

How can I make an entry in /etc/profiles because we have different groups of users and their login time are different for each groups and its user. I would like to make the restriction on groups basis since numbers of users is also very high, so it will be very difficult to make an entry in .profile of each users. So I would like to make the restriction for each groups having different working time and day.

 

So if I make an entry in /etc/profile it will effect all users. Right?

 

Appreciate you people all help.

 

Regards

Syed

Dennis Handly
Acclaimed Contributor

Re: Restricting user to login after their shift

>I would like to make the restriction on groups basis since numbers of users is also very high, so it will be very difficult to make an entry in .profile of each users. So I would like to make the restriction for each groups having different working time and day.

 

If each set of users is in a different Unix group, you can check that.

case $(id -ng) in

group1)  check limits ...  # insert logic from JRF's example

   ;;

group2)  check limits ...

   ;;

*)  # These are unlimited

   ;;

esac

 

>So if I make an entry in /etc/profile it will effect all users?

 

Only the ones you want it to do so.