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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I call a Unix shell script from within a Stored Procedure

Status
Not open for further replies.

JaneMosk

Programmer
Jul 2, 1999
7
US
I have a unix shell script which needs to run in the middle of a stored procedure process. Is there a way to kick this off and know when it's complete?<br>
Thanks
 
I am not aware of any such facility available on Sybase.&nbsp;&nbsp;If you get to know it, please mail me at <A HREF="mailto:srajesh@kanbay.com">srajesh@kanbay.com</A>
 
U could use the extended stored procedure xp_cmdshell 'shellscript.sh', [no_output] to do it if u r using ASE 11.5.x or higher. Assumption is that ur shell script is called 'shellscript.sh' and the user executing the same must also have appropriate user rights on the UNIX environment.

U could trap the return status into a sybase variable as u regularly do with other stored procedures.



Syntax

xp_cmdshell command [, no_output]

Parameters

command - is the operating system command string; maximum length is 255 bytes.

no_output - if specified, suppresses any output from the command.

Examples

1.xp_cmdshell 'copy C:\log A:\log.0102', no_output

Silently copies the file named log on the C drive to a file named log.0102 on the A drive.

2.xp_cmdshell 'date'

Executes the operating system's date command and returns the current date as a row of data.

Comments

·xp_cmdshell returns any output, including operating system errors, as rows of text in a single column.

·xp_cmdshell is run from the current directory of the XP Server.

·The width of the column of returned output is 80 characters. The output is not formatted.

·xp_cmdshell cannot perform commands that require interaction with the user, such as &quot;login&quot;.

·The user context in which an operating system command is executed via xp_cmdshell is controlled by the value of the xp_cmdshell context configuration parameter. If this parameter is set to 1 (the default), xp_cmdshell restricts permission to users with System Administration privileges at the operating system level. If this parameter is set to 0, xp_cmdshell uses the security context of the operating system account under which Adaptive Server is running. Therefore, using xp_cmdshell with the xp_cmdshell context configuration parameter set to 0, any user can execute operating system commands using the permissions of the account running Adaptive Server. This account may have fewer restrictions than the user's own account.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top