celtician
asked on
Authenticate using sesu from script
When i log into certain machine with my user name (username1) i don't have access to certain folders etc... however if use a sesu command and i log as another user (lets call it username2) i do have access (however and i dont know the reaseon, when i sesu username2 im not required for a password but im logged ok as that user) to the resources i need.
Now im developing a script fro my username1 that will require to log as username2 to be executed, by using a sesu, but somehow it does'nt work, it seems like i can't sesu from a script or even a command and execute the sript i want as username2 using the sesu option.
I get the next error on my unix console:
I execute:
And i get
Any ideas?
Now im developing a script fro my username1 that will require to log as username2 to be executed, by using a sesu, but somehow it does'nt work, it seems like i can't sesu from a script or even a command and execute the sript i want as username2 using the sesu option.
I get the next error on my unix console:
I execute:
opt/AB/AccessControl/bin/sesu - username2 /home/username1/scripts/script1.ksh
And i get
Invalid option /home/username1/scripts/script1.ksh
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@Murugesan - You're just repeating my suggestion to add the -c parameter.
@Gerwin Jansen,
I agree on repeating your suggestion.
However added use full path instead of using commands.
Example for egrep without using full path:
Sample OUTPUT:
Using - username2 -c /home/username1/scripts/sc ript1.ksh
and doing nothing for sesu
instead using actual action by /opt/AB/AccessControl/bin/ sesu
/bin/egrep username2 /home/username1/scripts/sc ript1.ksh
return value of egrep is [ 0 ]
Hence written the statement to use full path always.
Handling developer (either C++/C/java/shell script/batch) always to handle exception before writing the code during analysis itself.
I agree on repeating your suggestion.
However added use full path instead of using commands.
Example for egrep without using full path:
unset -f sesu
sesu ()
{
echo "Using $@"
echo and doing nothing for sesu
echo instead using actual action by /opt/AB/AccessControl/bin/sesu
Ret=$?
return $Ret
}
sesu - username2 -c "/home/username1/scripts/script1.ksh"
unset -f egrep
egrep ()
{
/bin/egrep "$@" >/dev/null 2>&1
#Writing echo to return zero instead of non zero due to /bin/egrep
echo "/bin/egrep $@"
Ret=$?
return $Ret
}
egrep username2 "/home/username1/scripts/script1.ksh"
echo "return value of egrep is [ $? ]"
Sample OUTPUT:
Using - username2 -c /home/username1/scripts/sc
and doing nothing for sesu
instead using actual action by /opt/AB/AccessControl/bin/
/bin/egrep username2 /home/username1/scripts/sc
return value of egrep is [ 0 ]
Hence written the statement to use full path always.
Handling developer (either C++/C/java/shell script/batch) always to handle exception before writing the code during analysis itself.
@celtician - why did you not assign any points to the first comment given? The answer you have chosen now is exactly what is being suggested in the first comment.
ASKER