Check when user exits SUDO


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check when user exits SUDO
# 1  
Old 06-09-2012
Question Check when user exits SUDO

Hello to everyone,

I'm new here and would like to thank everybody for the upcoming support, I know that I will have my question answered here, this community is huge. Smilie


First of all, I´m a DBA and work on a daily basis on Unix environments of all kinds (HP-UX, Solaris, AIX, etc). I have low knowledge on UNIX since I started messing with it for a short while.

Although I'm a DBA, I'm very curious to learn UNIX and Linux, because I used Windows for my entire life, now that I was introduced to UNIX I'm finding it awesome.

I have a question that you might help me with it:

For example, I have my username and password on all UNIX environments that we work, and to do DBA tasks, we must "sudo su - oracle" (to gain access to oracle user permissions), to do things related to oracle binaries.

What I'm trying to accomplish is, when we got our oracle crontab altered, when I do the first "exit" command (to exit sudo of oracle), I want to check that something is changed on the cron (like a commented line) and give me a warning message.

For example:

I'm logged into Oracle user by sudo'ing it. I edit the crontab (crontab -e), I put a # to comment a line on the cron then save it (we usually to this to avoid jobs running and erroring due to maintenance window). When I log out of Oracle by issuing "Exit", is there any way to display something like this:

"There is a commented job on your crontab, please check".

Well, of course my script will not have a history of the cron and will not do analysis of what actually is the current job commented. But only check for a special character (like #) or if something changed since the last login to oracle user.

Is that possible? I have little to almost none knowledge of shell scripting, so a patient explanation might be necessary.

Thank you very much for your support.
# 2  
Old 06-10-2012
Checking for commented line in crontab shouldn't be hard. The only thing is it might be achieved in different ways, depending on your environment. What shell are you using when logged into oracle user? Check it with grep oracle /etc/passwd(last column).
# 3  
Old 06-10-2012
Hi Bartus,

I did a quick check on our servers and they are all running ksh.
# 4  
Old 06-10-2012
Add this line to $ORACLE_USER_HOME/.kshrc:
Code:
alias exit='crontab -l | grep ^# > /dev/null && echo "There is a commented job on your crontab, please check"; exit'

# 5  
Old 06-10-2012
Wow!

Thanks a lot Bartus, I'll give it a try and post here the results.
# 6  
Old 06-12-2012
Bartus, I did not find the .kshrc file in my environment, but we use a .profile to load environments variables and I added your string there... It worked like a charm.

I have one more question:

Is there a way to filter the second character too? Like this:

If the second char is a number or an asterisk, show message, if any other char, does not show.

I was thinking of AWK to do this, but I'm not sure.
# 7  
Old 06-12-2012
Try:
Code:
alias exit='crontab -l | grep "^#[0-9*]" > /dev/null && echo "There is a commented job on your crontab, please check"; exit'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to check sudo access of other users?

Hi, I always use "sudo -U user -l" as root and it gives me list of sudo access, that person have. But on one Solaris server, I can't run it. recently only I installed latest patchset on this server. Not sure, if that changed something on this. However, sudo package is showing old one. # id -a... (1 Reply)
Discussion started by: ron323232
1 Replies

2. UNIX for Beginners Questions & Answers

Script to check if files exits

Hi In live system core files are generating frequently. around 10 core files in 30 mins in root file system. which is eating my space very much below is core file core.56539 core.78886 core.12302 core.80554 core.20147 I am trying to write a script which should move... (7 Replies)
Discussion started by: scriptor
7 Replies

3. AIX

Sudo to other user

Hello All, I am trying to grant sudo privileges to a set of users (say tom and jerry) to sudo to another set of users (jim, harry). This is because we don't want to disclose the password of jim and harry. I did defined the user_alias and runas alias. %wms ALL = (USR) /usr/bin/su -, where wms... (7 Replies)
Discussion started by: ibmtech
7 Replies

4. Shell Programming and Scripting

how to run a command as soon as user exits from session

I need to write a script, where I have to get names of files that are to be deleted from a user and have to delete those files when he exits session. How to set a particular command to be run as soon as user exits from a session? Can somebody help? I have to write a script on linux system.... (3 Replies)
Discussion started by: yashashri
3 Replies

5. UNIX for Dummies Questions & Answers

sudo su - USER ??? How to??

Hi folks, Here is my question of the day 8-) I have to provide the ability to sudo su - orapd2 & sudo su - pd2adm for the following people User A, B, C, D which all of them are part of the group staff. orapd2 and pd2adm are also users. Users A, B, C, D should not type the password for... (2 Replies)
Discussion started by: 300zxmuro
2 Replies

6. UNIX for Dummies Questions & Answers

sudo user

I am trying to run a command from different user on my server. However when i execute the command it asks for password can you please help. when i use this command to switch user no password is required 1) sudo su - bilbtf42 when i use 2) sudo su - bilbtf42 cp file1 direcotry1/file1 ... (3 Replies)
Discussion started by: blackeyed
3 Replies

7. AIX

sudo user access

I have installed sudo on AIX 6100-04 and want to know how do I set it up for a user to be able to run only some commands? I want to give the user the rights to only cd to certain directories and run the ls command to name a few? Are there any issues with running sudo when the user is forced to... (2 Replies)
Discussion started by: daveisme
2 Replies

8. AIX

How to check a script was started using 'sudo' ?

How can I from within a script, find out if that script was started using 'sudo' and by a valid soduer ? (1 Reply)
Discussion started by: Browser_ice
1 Replies

9. Linux

Sudo user vs RBAC

Hi all, What the difference between the sudo users & RBAC when the talk of effects after doing the above comes??? any differences between them ,kindly list ?? (1 Reply)
Discussion started by: saurabh84g
1 Replies

10. UNIX for Dummies Questions & Answers

scp with a sudo user

Morning guys, I'm hoping you can advise me as to whether or not the following is possible. Is there a way of firing off an scp command with a sudo user as the user? e.g. I am logged onto server1 as smith, but want to pull files from server2 that I can only read as sudo jones. In my mind it... (3 Replies)
Discussion started by: dlam
3 Replies
Login or Register to Ask a Question