Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can the su command execute a function

Status
Not open for further replies.

solvetek

Programmer
Jul 17, 2001
12
US

The su command changes user credentials to those of the root user or
to the user specified by the Name parameter, and then initiates a new
session.

su - oratest -c "command text"

is it possible for the "command text" to be an inline function instead
of a command or script? Here is my code. The error I get is "ksh:
file_remove: not found."


#!/bin/ksh
##sample code
function file_remove
{
cd $1
find . -name \*.trc -mtime +$2 -exec rm {} \;
}
su - oratest "-c file_remove $ORACLE_HOME/admin/bdump 60"
 
I don't *think* so, an interesting idea though.

The problem I see with that (and I can't test it at the moment) is that su starts another shell and the function you've defined won't (I think) be visible to it.

There's an easy workaround though:

#!/bin/ksh
##sample code

print '
#!/bin/ksh
function file_remove
{
cd $1
find . -name \*.trc -mtime +$2 -exec rm {} \;
}
file_remove $ORACLE_HOME/admin/bdump 60
' > file_remove.ksh

su - oratest -c file_remove.ksh
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Thanks,


I was just trying to avoid 2 scripts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top