Link to home
Start Free TrialLog in
Avatar of mirde
mirdeFlag for Canada

asked on

How to trap who is running a script and log it?

Hello,

I have a script that can be executed by processes or users on our AIX box, the script contains the following:

#!/bin/sh
DLC=${DLC-/usr1/dlc};export DLC
PROSHUT=${PROSHUT-$DLC/bin/_mprshut}
trap "" 13
exec $PROSHUT "$@"

Open in new window


How can I edit the above code so that it traps which process or user is running the script and log it to a file? Would there be something I can add to the code in the original file?

Thanks.
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

you can add line at the beginning of the script

username >> /path/to/logfile

the file logfile should be writable by all users
Sure, just put something like this into it:
echo `date`  `whoami` >> /tmp/spy.out

Open in new window


That will log the user with a timestamp to the file /tmp/spy.out
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There are many options.
Is this an SUID script.
AIX does not support SUID scripts.
Avatar of Tintin
Tintin

There are almost no *nix versions that support SUID scripts.

woolmilkporc's solution is the best as you can restrict the permissions on the log file.
You could have each user append data to a <username> named file and have a process that monitors this directory that would take the data and add it into a file that the users/processes  have no access to.
Avatar of mirde

ASKER

worked like a charm