You can do:
sudo -iu bigadmin /path/to/myscript
Question
Consider this sudo - I am logged in as jonhnd and run this through a script run1st.ksh that has the below command
sudo -iu bigadmin
This elevates my credentials to bigadmin a generic user but that user is a 'shared' user meaning - I really dont have any leeway to customize his personal profile After he is logged in ,I see his PATH variable is very skinny ,with just few paths added
echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/opt/dell/srvadmin/bin
so the pwd is not in the path and neither would be executable . No of those dir's in the $PATH is writable and like I said modifying any personal files of bigadmin isn't an option. I have a start up script I execute as that user for just my sessions and I have to force execute it
. ./myscript
will work
myscript
. myscript
gives myscript not found error understandably because the path restrictions mentioned above. What I want to do is this run the sudo and myscript in run1st.ksh so that when I enter that bigadmin prompt myscript has already run @barmar thanks for helping . here is the o/p from running that ( put verbose on set -x )
++ sudo -iu bigadmin ksh -c '. ./run1st.ksh'
Usage: . [ options ] name [arg ...]
@Barmar
sudo -iu bigadmin ksh -c '/home/bigadmin/run1st.ksh'
ksh: line 1: /home/bigadmin/run1st.ksh: not found
sudo -iu bigadmin ksh -c '. /home/biadmin/run1st.ksh'
age: . [ options ] name [arg ...]
$ sudo -iu bigadmin ksh -c '. /home/bigadmin; run1st.ksh'
+ sudo -iu bigadmin ksh -c '. /home/bigadmin; run1st.ksh'
Usage: . [ options ] name [arg ...]
$ sudo -iu bigadmin ksh -c '. /home/bigadmin/run1st.ksh ; run1st.ksh'
+ sudo -iu bigadmin ksh -c '. /home/bigadmin/run1st.ksh ; run1st.ksh'
Usage: . [ options ] name [arg ...]
does not work
$ sudo -iu bigadmin /home/bigadmin/run1st.ksh
+ sudo -iu bigadmin /home/bigadmin/run1st.ksh
-nologin: line 1: /home/bigadmin/run1st.ksh: not found
It actually look for the run1st.ksh in johnd 's directory
$ sudo -iu bigadmin echo `pwd`
++ pwd
+ sudo -iu bigadmin echo /home/johnd
and even after copying it to johnd 's home- I get the SAME File not found command . So its looking for the file in specific PATH and not in the directory you put forth . Maybe tweak PATH in that sudo command ?
there was a space in the filename xxx. ksh
that I did'nt notice. Fixed that and now it does not give file not found error BUT it executes it and returns back to the johnd prompt.
$ sudo -iu bigadmin /home/bigadmin/run1st.ksh
+ sudo -iu bigadmin /home/bigadmin/run1st.ksh
++ printf '\033]0;%s@%s:%s\007' johnd server400 '~'
$
No correct solution
OTHER TIPS
You can do:
sudo -iu bigadmin /path/to/myscript