How to kuu to another id inside a shell script

I need to kuu within a script and then exit from the kuu id within the same script. How can I do that?




#!/bin/ksh

cd ~

filename = $(ls -ltr | awk 'END{print $NF}'
kuu pfndqa
./run-dfp.sh qae2e first /v/TgtFiles/$filename
exit
cd /v/region/na/appl/

Open in new window

sunny82Asked:
Who is Participating?
 
woolmilkporcConnect With a Mentor Commented:
Hi,

I never heard of "kuu".

Seems that it does the same as "su", and with su it could look like this

#!/bin/ksh  
...
 ...
su pfndqa -c "./run-dfp.sh qae2e first /v/TgtFiles/$filename"
cd /v/region/na/appl/
...

wmp
0
 
sunny82Author Commented:
On doing kuu here, it is asking me for pasword but on putting the password, it should execute the following shell script. But it is not getting executed. After executing the shell script, it should then exit the kuu id
0
 
woolmilkporcCommented:
... and the statement in line 5 will most probably not do what you want.

I assume you're trying to find the newest file in the directory.
This is easier:

filename=$(ls -tr | tail -1)

Note that I removed the spaces around "=". They're not allowed when assigning variables.


0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
sunny82Author Commented:
Thx so much..let me try this tomorrow and I will let you know...I am assuming that after doing su and calling this shell script from another perl or shell script, it will ask for my password and after executing line 7 will exit the su and return to my actual user id. Am I correct?
0
 
woolmilkporcCommented:
Yes, correct.
Just note that everything you want to execute as pfndqa must appear after "-c" and must be enclosed in quotes.
In your case use double quotes, because there is the local variable $filename which needs to get expanded by the calling shell, not the subshell opened by "su".
Should you need double quotes inside the command executed via "su" escape them with a backslash (\")
You don't need an explicit "exit". When the command specified with -c "..." ends the subshell ends as well.
0
 
sunny82Author Commented:
great that helped a lot. Thx..I would like to know the difference between su and kuu...Don't both do the same thing?
0
 
woolmilkporcCommented:
I still have no idea what kuu actually is. Nerver heard of it before, and searching the web doesn't yield any suitable result.
Could it be that kuu is an alias or a link?
Please issue
alias kuu
type kuu
ls -l $(which kuu)
Any insight?
Thx for the points!
wmp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.