?
Solved

unix profile file

Posted on 2011-10-28
24
Medium Priority
?
373 Views
Last Modified: 2012-05-12
i have a HPUX server and there are several users who all have their own directories in the /home directory.
in each of these /home/user directories, there is a .profile file. if i what to keep a user out of our software, i comment out the last line of their .profile file.
if i want to comment out the last line of most but NOT all of the users, is their an easy way to do this without editing each individual file? there are several users and editing each file would take a long time.
0
Comment
Question by:JeffBeall
  • 15
  • 8
24 Comments
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048371
Preventing certain users from running specific applications should probably be handled a different way.

What is the last line in the .profile?
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 37048410
exec $UDTBIN/udtts
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048452
So commenting that out isn't going to prevent users from executing that application, but rather it will just not start automatically when they login... they can still invoke it manually if they wanted.

One fix for this is could be to use groups and chmod/chgrp.

Example:
Create new group in /etc/group -- let's call it udt
Add all users who you want to be able to run udtts to group udt
chgrp udt $UDTBIN/udtts
chmod 750 $UDTBIN/udtts

The only issue I can think off the top of my head is that users who aren't in group udt, but have that exec line in their .profile will probably get an error each time they log in.  A fix for that could be to just remove that line from all .profile's and instructing your users to just invoke $UDTBIN/udtts manually.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 400 total points
ID: 37048469
for dir in  /home/*
do
    sed -i "s/^exec \$UDTBIN\/udtts/#&/" $dir/.profile
done
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 37048480
nobody at my work know unix, i'm pretty much the only one, so it wouldn't be a problem of someone invoke it manually.
i could try the group thing, it would only be temporary because i just need to lock out people for a few days while we do inventory.
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048483
Hey farzanj :)

Only problem with that is he doesn't want it disabled for all users, only some.

If you have a list of users that you want to disable this for in .profile instead of doing the whole group thing, then that can easily be done with a modified version of what farzanj posted.

In the end it's up to you really, both are valid solutions.  Since this is temporary however (which I didn't know at first) you should probably do the for loop.

0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048491
/tmp/userlist should be the list of users you want to disable, 1 on each line.

userlist=`cat /tmp/userlist`
for dir in  /home/$userlist`
do
    sed -i "s/^exec \$UDTBIN\/udtts/#&/" $dir/.profile
done

Open in new window


That should suffice farzanj, yes?  Can't test right this second.
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 37048498
does

sed -i "s/^exec \$UDTBIN\/udtts/#&/" $dir/.profile

disable all users?
does it comment out the last line?

maybe that would be ok, i could disable everyone, then just enable the few that needs to do things
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048506
disable all users?
Yes
does it comment out the last line?
Yes

My last example (modified farzanj's answer) will work from a list of users.  There might be a "cleaner" way to do it (can't test right now), but that syntax should suffice.
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 37048514
so i would have to be in the /home directory?
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048524
Nope all of the paths in that example are absolute so it can be ran from anywhere.
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048525
@farzanj -- if you have further comments, by all means please add them :)
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 37048530
could i do this command so that it affects one user as an experiment so that i could see if it works before i do it on all the users?
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048541
Absolutely, and that is a wise thing to do.  To test with just one user, only list that one user in /tmp/userlist.

create a script for this, like /tmp/userappfix.sh

#!/bin/bash
userlist=`cat /tmp/userlist`
for dir in  /home/$userlist`
do
    sed -i "s/^exec \$UDTBIN\/udtts/#&/" $dir/.profile
done

Open in new window

chmod +x /tmp/userappfix.sh
/tmp/userappfix.sh

Open in new window

0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048552
Woops found a small typo in farzanj's example, and therefore in mine.

#!/bin/bash
userlist=`cat /tmp/userlist`
for dir in  /home/$userlist`
do
    sed -i "s/^exec\ $UDTBIN\/udtts/#&/" $dir/.profile
done

Open in new window

0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048555
This should work too.

#!/bin/bash
userlist=`cat /tmp/userlist`
for dir in  /home/$userlist`
do
    sed -i "s?^exec $UDTBIN/udtts?#&?" $dir/.profile
done

Open in new window

0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048561
Hah scratch those last 2 posts -- farzanj was either correct or just missed a \ instead of typo'ing where it should be.  I wish I could test this right now -- not entirely certain if you need to escape the space if the string is in double quotes...  farzanj where did you go?  :p

#!/bin/bash
userlist=`cat /tmp/userlist`
for dir in  /home/$userlist`
do
    sed -i "s/^exec\ \$UDTBIN\/udtts/#&/" $dir/.profile
done

Open in new window

0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048567
Try this first, using the sed syntax provided by farzanj
#!/bin/bash
userlist=`cat /tmp/userlist`
for dir in  /home/$userlist`
do
    sed -i "s/^exec \$UDTBIN\/udtts/#&/" $dir/.profile
done

Open in new window

If that doesn't work as expected then try
#!/bin/bash
userlist=`cat /tmp/userlist`
for dir in  /home/$userlist`
do
    sed -i "s/^exec\ \$UDTBIN\/udtts/#&/" $dir/.profile
done

Open in new window


Sorry for the spam! :)
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 37048570
no problem, just trying to catch up.
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37048601
Answering from an iPad is definitely not ideal :)

Note taken.
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 37049955
sed -i "s/^exec \$UDTBIN\/udtts/#&/" $dir/.profile

i have HPUX and i think it doesn't like the -i

i get this

sed: illegal option -- i
Usage: sed [-n] [-e script] [-f source_file] [file...]

any ideas? i tried the man page, it's a little hard to follow.
0
 
LVL 21

Accepted Solution

by:
Papertrip earned 1600 total points
ID: 37050192
Ah yes, non-GNU sed.  Try the following with only your test user in /tmp/userlist

#!/bin/bash
userlist=`cat /tmp/userlist`
tmpfile=/tmp/profile.tmp
for dir in  /home/$userlist`
do
    sed "s/^exec \$UDTBIN\/udtts/#&/" $dir/.profile > $tmpfile && mv $tmpfile $dir/.profile
done

Open in new window

0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37050219
You can alternatively install GNU sed on your machine which supports in-line editing with -i

http://hpux.connect.org.uk/hppd/hpux/Gnu/sed-4.2.1/
0
 
LVL 1

Author Closing Comment

by:JeffBeall
ID: 37050755
thanks for the help,
Papertrip you clearly did the most work, so i gave you the most points,
thanks again.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month7 days, 22 hours left to enroll

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question