Ignore "a line" within /etc/profile only when su'ing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ignore "a line" within /etc/profile only when su'ing
# 8  
Old 01-30-2009
Quote:
Originally Posted by lwif
I tried using "awk 'NR==1{next}1'" but I get this error -
awk: syntax error near line 1
awk: bailing out near line 1

I would rather not edit the scripts - becasue there are many. I want to be able to place some logic in the /etc/profile to determine is the user is changed by using su then ignore the command.
Use nawk or /usr/xpg4/bin/awk on Solaris.

Regards
# 9  
Old 01-30-2009
Or test the three UID's of the process
Code:
#include <unistd.h>
#include <stdio.h>

/*  iamsu.c 
   return zero if real effective and saved uid's do not match
   ie., su'ed process
*/
int main(void)
{
	uid_t real=0;
	uid_t effective=0;
	uid_t saved=0;
	int retval=0;
	
	getresuid (&real, &effective, &saved);
             retval=(real==effective && effective==saved) ? 1 : 0;

	return retval;
}

Code:
# 
iamsu ||  ## bit of code you want to run only when NOT su'ed ##
# or
iamsu
if [[ $? -eq 1 ]] ; then
      echo 'i am not su'
else
      echo 'i am su '
fi

# 10  
Old 01-30-2009
I guess when you do su - oracle, the value of whoami would be oracle...

Probably you could put a check in your .profile file something like this:

Quote:
if [[ whoami -ne "oracle" ]]; then
echo "^[]2;$(hostname)-(ABC) @ $(who am i)^G"
fi
Hope this helps...

regards,
Arun.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Permission error when "touch"ing file with different user

Hi, There are 2 users (T886072 & T864764) that need to be provided full (rwx) access to a directory. I made the changes to the directory permissions using chmod and setfacl : root@digidb2:# chmod 700 /u02/ftpfiles/MFRS16/discount_rates/ root@digidb2:# setfacl -s... (3 Replies)
Discussion started by: anaigini45
3 Replies

2. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

3. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

4. Shell Programming and Scripting

Move a line containg "char" above line containing "xchar"

Okay, so I have a rather large text file and will have to process many more and this will save me hours of work. I'm not very good at scripting, so bear with me please. Working on Linux RHEL I've been able to filter and edit and clean up using sed, but I have a problem with moving lines. ... (9 Replies)
Discussion started by: rex007can
9 Replies

5. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. UNIX for Dummies Questions & Answers

Where can I read about the difference between "..profile" and ".profile"

Hi I know from reading O Riley's Classic Shell Scripting' that the .profile file is " the shells configuration file" but I am unable to find a reference to what "..profile" means. I have searched on the net, Sams Teach Yourself Unix, Unix Visual Quickstart Guide and Linux in a Nutshell. I have... (2 Replies)
Discussion started by: zorrokan
2 Replies

10. UNIX for Dummies Questions & Answers

"vi"-ing a constantly updated file

Hi, A bit of a dumb question here. Sorry folks. Suppose I have this file which is being updated at irregular intervals (a few seconds, a few minutes, who knows) by a background process. I 'vi' this file with the intention of editing it, so it opens up a temp copy as the usual... (8 Replies)
Discussion started by: Percy
8 Replies
Login or Register to Ask a Question