Removing user access using user id


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing user access using user id
# 1  
Old 01-18-2011
Removing user access using user id

I have multiple .prm files that contain user ID's. The .prm files reside in multiple directories that allow users access to different areas of the system. (see below)



Code:
 
 
current directory /apps/fourgen/accounting/menu
 
 
drwxrwxrwx  16 phil     infotech     512 Sep  7  2002 apmenu
drwxrwxrwx  14 phil     infotech     512 Sep  7  2002 armenu
drwxrwxrwx  12 phil     infotech     512 Sep  7  2002 armenu.orig
drwxrwxrwx   3 phil     infotech     512 Sep  7  2002 barmenus
drwxrwxrwx   5 phil     infotech     512 Sep  7  2002 cismenus
drwxrwxrwx  13 phil     infotech     512 Feb  2  2006 cmpmenus
drwxrwxrwx   6 phil     infotech     512 Sep  7  2002 cssmenus
drwxrwxrwx   9 phil     infotech     512 Sep  7  2002 cstmenus
drwxrwxrwx  10 phil     infotech     512 Sep  7  2002 famenu
drwxrwxrwx   6 phil     infotech     512 Sep  7  2002 famenus
drwxrwxrwx  14 phil     infotech     512 Sep  7  2002 glmenu
drwxrwxrwx  10 phil     infotech     512 Sep  7  2002 icmenu
drwxrwxrwx   7 phil     infotech     512 Sep  7  2002 incmenus
drwxrwxrwx   7 phil     infotech     512 Sep  7  2002 lblmenus
drwxrwxrwx   7 phil     infotech     512 Sep  7  2002 mainmenu
drwxrwxrwx   3 phil     infotech     512 Sep  7  2002 matmenus
drwxrwxrwx   8 phil     infotech     512 Sep  7  2002 mcmenu
drwxrwxrwx   8 phil     infotech     512 Sep  7  2002 mkcmenus
drwxrwxrwx  20 phil     infotech     512 Sep  7  2002 mktmenus
drwxrwxrwx  43 phil     infotech    1024 Sep  7  2002 oemenu
drwxrwxrwx  10 phil     infotech     512 Sep  7  2002 oemenu.orig
drwxrwxrwx  10 phil     infotech     512 Sep  7  2002 paymenus
drwxrwxrwx  13 phil     infotech     512 Sep  7  2002 pumenu
drwxrwxrwx   8 phil     infotech     512 Sep  7  2002 schmenus
drwxrwxrwx   5 phil     infotech     512 Sep  7  2002 stkmenus
drwxrwxrwx  10 phil     infotech     512 Sep  7  2002 sysmenus
drwxrwxrwx   7 phil     infotech     512 Sep  7  2002 tckmenus
drwxrwxrwx   5 phil     infotech     512 Sep  7  2002 wtymenus
 
"$LOGNAME>" cd ../mainmenu
"V880-PROD:$PWD"
"$LOGNAME>" ls
admin    company  main     mtax     mtxact
"V880-PROD:$PWD"
"$LOGNAME>" cd main
"V880-PROD:$PWD"
"$LOGNAME>" ls
1            3            4.prm        7            9            b.prm        core         menu.act     t            z
1.prm        3.prm        5            7.old        9.prm        c            env.out      menu.help    t.prm        z.help
1.prm.old    3.prm.old    5.prm        7.prm        a            c.prm        i            menu.old     tck788.sql   z.prm
2            3f.prm       6            8            a.prm        company.act  i.prm        s            w
2.prm        4            6.prm        8.prm        b            company.img  menu         s.prm        w.prm
 
vi 1.prm
 
#National
:allow:davidw,simonk,katrinad,elizabeo,maryd,rachelm,jodiew,carolep,timj,colleenh,audreys,angelal:
:allow:jamesm,rachel,gareth,jonathan,anthonyp,wedzerai,markink,nikkip,gail,robynet,naomil,alanaj,beverley,markl:

I need to remove a users access using their user id which resides in all the .prm files under the directory /apps/fourgen/accounting/menu
I have searched for user id, output to a text file and used sed to remove userid

Code:
 
find . -type f -name '*.prm' | xargs grep maryd > remove.txt
sed -e  's/maryd,//g' -e 's/maryd//g' < remove.txt > tofile.txt

When the user access was created the user id can be added to the middle of the line or at the end of the line hence the maryd, and maryd. I need to
remove both to keep the functionality of the file correct.

How do I get something like this into a script to remove the user id from all .prm files?
# 2  
Old 01-18-2011
Hi

if i understood you correctly, just put those two commands in a file and run the file, something like:

Code:
#cat users.sh
find . -type f -name '*.prm' | xargs grep maryd > remove.txt
sed -e  's/maryd,//g' -e 's/maryd//g' < remove.txt > tofile.txt

#chmod 755 users.sh
#./users.sh

Of course, you would like to get the maryd as an input to the script. You can use the read command for the same.

Guru.
# 3  
Old 01-18-2011
Code:
name="maryd"
find . -type f -name '*.prm' -exec grep $name {} \;> remove.txt
sed -e  "s/$name,*//g"  < remove.txt > tofile.txt


If you need update the prm file directly, try this:
(be careful, test the command in temp folder and temp files first)
Your sed need support -i option.
Code:
name="maryd"
find . -type f -name "*.prm" -exec sed -i "s/$name,*//g" {} \;

# 4  
Old 01-18-2011
Be carefull with your second replace, say you run for user "mark" then "markl" would be changed to "l"

Probably be better of with something like:
Code:
sed -e "s/,${name},/,/g" \
    -e "s/:${name}[:,]/:/" \
    -e "s/,${name}:/:/" < remove.txt > tofile.txt

# 5  
Old 01-20-2011
Thanks for the feedback folks.

I would like to update the .prm files directly however the -i option is not supported. Is there another way to do this? ie input changes back into
all the .prm files
# 6  
Old 01-20-2011
Probably best to output to a temporary file and cat this over the original:

Code:
sed -e "s/,${name},/,/g" \
    -e "s/:${name}[:,]/:/" \
    -e "s/,${name}:/:/" < $PERMFILE > /tmp/prm_tmp_$$
cat /tmp/prm_tmp_$$ > $PERMFILE
rm /tmp/prm_tmp_$$


Last edited by Chubler_XL; 01-20-2011 at 08:13 PM.. Reason: typo
# 7  
Old 01-26-2011
Chubler_XL

If I output to a temporary file, how do I cat over the original file when there are entries from multiple files in the temporary file. How do I change all .prm files directly in directories, sub directories from the current working directory /apps/fourgen/accounting/menu. Im fine with the sed synatx.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

User permission access

Hi folks, I am trying to grant the access like below items using the setfacl command, but i couldn't achieve as what I required. any other possibility. username : testing Readonly access in /form_dl/system/prd/logs Write only access in /form_dl/system/prd/deploy No access to other... (0 Replies)
Discussion started by: gsiva
0 Replies

2. AIX

Removing the password of a user

Hi Experts, According to the manual if you want to remove the password for a user account the "password" field in /etc/security/passwd should be set to "*" So instead of this: password = 6BqaLx8FeI8os Should be set to this: password = * But when I run the following command in my AIX... (5 Replies)
Discussion started by: livehho
5 Replies

3. UNIX for Advanced & Expert Users

Need help about user access

Hi frds, I have got a script restart.sh that kills and restarts a process. This scripts runs under a user called USER1 who is a normal user. Now my requirement is that i got other user named USER2 who should be able to run that script as USER1 as we dont want to share the password of user1 we... (2 Replies)
Discussion started by: phanidhar6039
2 Replies

4. Solaris

User access on Solaris

Hi There I am having trouble in solving a scenario. We have some test systems on the network where users can login as themselves. These systems are connected to the LDAP server and authentication happens without any issues. These systems are used to create flars which are used to jumpstart other... (0 Replies)
Discussion started by: sinfuldips
0 Replies

5. AIX

Limit user access

We have gotten an application that will read and display logs in a report format. The application need a user name and password to access the AIX servers where the logs reside. My problem is the logs are in a few different file systems on the server. Is there any way to lock the user to only the... (1 Reply)
Discussion started by: daveisme
1 Replies

6. UNIX for Advanced & Expert Users

Determining if user is local-user in /etc/passwd or LDAP user

Besides doing some shell-script which loops through /etc/passwd, I was wondering if there was some command that would tell me, like an enhanced version of getent. The Operating system is Solaris 10 (recent-ish revision) using Sun DS for LDAP. (5 Replies)
Discussion started by: ckmehta
5 Replies

7. AIX

User access

Is there any way I can restrict a user to 1 directory when logging in but give the access to another directory? For example restrict the user to /home/user at login but also allow then to access /opt/data/user. (1 Reply)
Discussion started by: daveisme
1 Replies

8. Red Hat

New RH User - Access Denied

Hi, We were just recently given a new VM instance with Red Hat linux. The only user account that can log in successfully is the root account. I made sure that the user z021407 has access to their directory and the account can read the home directory, but I can't log in with the new account... (2 Replies)
Discussion started by: edrichard
2 Replies

9. UNIX for Dummies Questions & Answers

removing a user with hidden files

Hello, I am trying to remove an employing from our database, I have removed all her files but can't remove the directory because of the hidden files. How do I remove the user? Thanks, (1 Reply)
Discussion started by: nov_user
1 Replies

10. UNIX for Dummies Questions & Answers

FTP user access

I created a user which I would like to have access only to FTP. I am able to get FTP to the machine with that user, but I only want him to have access to two directories, and no shell access. How can I accomplish this? Thanx, Aaron (1 Reply)
Discussion started by: Spetnik
1 Replies
Login or Register to Ask a Question