Operating System - HP-UX
1825950 Members
2849 Online
109690 Solutions
New Discussion

Re: unix script how to question

 
Jim Galliher
Advisor

unix script how to question

I have a menu script that allows users (that belong to multiple groups) to choose to go to different environments with different group permissions and then when they exit it brings them back to the menu. I would like to set their primary group to the environment that they go into so when they create a file it keeps the group ownership standard. If I was doing this manually, I would do it with the newgrp command. However the newgrp command creates a new shell and when the user exits the environment, it exits the script instead of looping through and giving the user the option menu. Any thoughts how I can do what I would like.
8 REPLIES 8
Sandman!
Honored Contributor

Re: unix script how to question

Hi Jim,

Assuming your menu-driven script is modularized w/ the use of functions, you might want to "return" instead of "exit" from the subshell created.

If you could attach your script then that would be most helpful in troubleshooting.

thanks!
James R. Ferguson
Acclaimed Contributor

Re: unix script how to question

Hi Jim:

Create your menu script and make it the one specified in the shell field of '/etc/passwd'. In this fashion, any user of this account will be confined to your menu script when they login.

Offer the option in your menu of changing to a new group, using 'newgrp group'.

Offer any other options you want. Use an 'exit' in your menu script to log-off.

Regards!

...JRF...
Jim Galliher
Advisor

Re: unix script how to question

A little more in depth discussion of the script... The script presents the user a list of multiple environments to choose from. Each one of these environments has its own specific group. A user can belong to more than one group so when they make a selection it is desired to have the effective group of the environment they choose. The desired effect of the script is to drop the user to a unix shell in the correct enviroment with certain environment variables already set for them. When they exit the shell it returns them to the menu where they can select another environment and drop to another shell with another set of environment variables set and so on and so on. The problem with is newgrp creates another shell and takes the existing environment variables which is good, but when they return or exit they are no longer in the menu script program, based on the script being exec'd out of their profile, it would then exit the system.
Sandman!
Honored Contributor

Re: unix script how to question

Hi Jim,

Take a look at this TKB document, might be relevant to your needs...

http://www1.itrc.hp.com/service/cki/docDisplay.do?docLocale=en_US&docId=200000065953684

cheers!
rmueller58
Valued Contributor

Re: unix script how to question

Jim,

As an example we have a menuing system (homebuilt) to define specific database variables for different "groups"..

with you could call a function with the menu or call a sub shell to define variables.

We define $HOME as

/home/$group/$user

the $group defines the variable subset you will want to construct. You have to think our your process of creating users in advance.


rmueller58
Valued Contributor

Re: unix script how to question

for each "school district" we have our helpdesk needs to be able to get into several different databases at any given time without the typing out the variables

For all database users their is a set of GLOBAL and LOCAL variables.

We tied the USER to DISTRICTID.

DISTRICTID would be the equivalent to your GROUP although we are not using groups, we use the "$PATH" for /home/$DISTRICTID/ to define more local variables.

in the Base PATH of each district we have a seed file defining the "$DISTRICTID

/home/district/seedfile

in the menu We have a statement that reads in the variable:

cat ../seedfile |export IID=`awk '{print $1}'`

if you view the seedfile, it contains three characters. from it we define Database variables. You can setup a CASE statement in your menu to call specific district information as well.

clear
echo '

which database would you like to use:
1.) FINANCE DATABASE
........

s.) Sub Database - Production
Please select from one of the above: \c'

read choice
echo


case "$choice" in
1)PEIDBNAME=finance;;
...................

s)PEIDBNAME=subfin;;
*). dbmenu;;
esac
export PEIDBNAME
echo $PEIDBNAME
fi




Jim Galliher
Advisor

Re: unix script how to question

Sandman,
I reviewed your article and I tried just copying the script in the article you referenced, but the script only output from "part 1 is executing", the part 2 and part 3 never came to the screen. Any thoughts?


Rex, I appreciated your input, in this situation the customers are seperated by unix groups because of data confidentiality. That is why I need "master users" to be able to work with the correct group in any given account.

I am thinking about a perl script that can fork off processes to handle making the correct group available based upon the environment they are working in.


Darran Rice
New Member

Re: unix script how to question

Jim,

I read this topic with interest as I have almost exactly the same issue, with newgrp starting a new shell when I actually just want it to set the group and continue execution of my script. I noticed the thread seemed to die a few months ago and was just wondering if you ever came up with a solution or work around? There has been the suggestion of the use of ACLs, but I would much rather use group based permissioning if at all possible. Any help you (or anyone else for that matter) can give on this topic much appreciated.

Regards,

Darran Rice