Run a shell command using Pl/Sql
hi all
i wonder if anyone knows a way to run a shell command using pl/sql
other than java stored procedure
as it seems not to be working in my case
thanx in advance,
Rasha
ofcourse not
i sent it once then i've got disconnected from interent then i reconnected
and resend my question so it was sent twice
now i hope you can answer my question !!!
Do you really think when asking twice or more often you will get a quicker answer?
Similar Messages
-
Power Shell Command using CSOM
Hi,
We have prepared a Power Shell command using Client Side scripts as per client requirements. The client did not had access to the SharePoint Server. So, PS commands with
server side scripts was out of scope.
The client requirement was to delete all the permissions on the list that was being inherited from site. Since the number of users were huge, so deleting all the users using ribbon was not possible.
Please have a look at the scripts below and let me know your feedback. If you have better suggestion than this, please let me know.
#location of client dlls on users' local system
$loc = "C:\SharePoint\ClientDLL"
//SharePoint Site URL
$siteUrl = ""
#Write your Login ID
$loginname = ""
#Write the Name of the List
$listname = ""
Set-Location $loc
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")
Write-Host "Please enter password for $($siteUrl):"
$pwd = Read-Host -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
Try
# Remove or replace line below to change authentication method
$ctx.Credentials = New-Object System.Net.NetworkCredential($loginname, $pwd)
$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()
#Write-Host "Current web title is '$($web.Title)', $($web.Url)"
$list = $Web.Lists.GetByTitle($listname);
$ctx.Load($list);
$ctx.ExecuteQuery();
Write-Host "Deleting Permissions on List : $($list.Title)"
if($list.HasUniquePermissions)
#Write-Host "Has Unique Permissions"
$list.ResetRoleInheritance()
$list.BreakRoleInheritance($false, $true)
Write-Host "Permissions deleted" -foregroundcolor Green
if(-not $list.HasUniquePermissions)
#Write-Host "Does not has Unique Permissions"
$list.ResetRoleInheritance()
$list.BreakRoleInheritance($false, $true)
Write-Host "Permissions deleted" -foregroundcolor Green
Catch
Write-Host "Some Error, Please Contact Administrator" -foregroundcolor Red
return
$list.Update()
$ctx.ExecuteQuery();
Regards,
Sudheer
Thanks & Regards, SudheerHi Sudheer,
In Client-Side, we can also use .NET Client Object Model to achieve your requirement.
Remove permission in Sharepoint List using Client Object Model
https://rambabualaparthi.wordpress.com/2013/12/30/remove-permission-in-sharepoint-list-using-client-object-model/
In order to better manage SharePoint in Client side, I suggest develop a Winform or WPF application and use .Net Client Object Model to achieve some requirements.
Best Regards
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
Run shell commands using java program
Hi guys,
I am trying to run shell commands like cd /something and ./command with arguments as follows, but getting an exception that ./command not found.Instead of changing directory using "cd" command I am passing directory as an argument in rt,exec().
String []cmd={"./command","arg1", "arg2", "arg3"};
File file= new File("/path");
try{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd,null,file);
proc.waitFor();
System.out.println(proc.exitValue())
BufferedReader buf = new BufferedReader(new InputStreamReader(proc.getInputStream()));
catch(Exception e)
{e.printStackTrace();
So can anyone please tell me what is wrong with this approach? or is there any better way to do this?
Thanks,
Hardikwarnerja wrote:
What gives you the idea that the process to execute is called "./command"? If this is in Windows, it is "cmd.exe" for example.It does not have to be cmd.exe in Windows. Any executable or .bat file can be executed as long as one either specifies the full path or the executable is in a directory that is in the PATH.
On *nix the file has to have the executable bit set and one either specifies the full path or the executable must be in a directory that is in the PATH . If the executable is a script then if there is a hash-bang (#!) at the start of the first line then the rest of the line is taken as the interpreter to use. For example #!/bin/bash or #!/usr/bin/perl .
One both window and *nix one can exec() an interpreter directly and then pass the commands into the process stdin. The advantage of doing this is that one can change the environment in one line and it remains in effect for subsequent line. A simple example of this for bash on Linux is
import java.io.OutputStreamWriter;
import java.io.Writer;
public class ExecInputThroughStdin
public static void main(String args[]) throws Exception
final Process process = Runtime.getRuntime().exec("bash");
new Thread(new PipeInputStreamToOutputStreamRunnable(process.getErrorStream(), System.err)).start();
new Thread(new PipeInputStreamToOutputStreamRunnable(process.getInputStream(), System.out)).start();
final Writer stdin = new OutputStreamWriter(process.getOutputStream());
stdin.write("xemacs&\n");
stdin.write("cd ~/work\n");
stdin.write("dir\n");
stdin.write("ls\n");
stdin.write("gobbldygook\n"); // Forces output to stderr
stdin.write("echo $PATH\n");
stdin.write("pwd\n");
stdin.write("df -k\n");
stdin.write("ifconfig\n");
stdin.write("echo $CWD\n");
stdin.write("dir\n");
stdin.write("cd ~/work/jlib\n");
stdin.write("dir\n");
stdin.write("cat /etc/bash.bashrc\n");
stdin.close();
final int exitVal = process.waitFor();
System.out.println("Exit value: " + exitVal);
}One can use the same approach with Windows using cmd.exe but then one must be aware of the syntactic differences between commands running in .bat file and command run from the command line. Reading 'help cmd' s essential here.
The class PipeInputStreamToOutputStreamRunnable in the above example just copies an InputStream to an OutputStream and I use
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class PipeInputStreamToOutputStreamRunnable implements Runnable
public PipeInputStreamToOutputStreamRunnable(InputStream is, OutputStream os)
is_ = is;
os_ = os;
public void run()
try
final byte[] buffer = new byte[1024];
for (int count = 0; (count = is_.read(buffer)) >= 0;)
os_.write(buffer, 0, count);
} catch (IOException e)
e.printStackTrace();
private final InputStream is_;
private final OutputStream os_;
} -
Hi i´m having trouble using this:
http://asktom.oracle.com/pls/ask/f?p=4950:8:6113176678923179734::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:16212348050
the code i used is:
create or replace procedure host( cmd in varchar2 ) as
status number;
begin
dbms_pipe.pack_message( cmd );
status := dbms_pipe.send_message( 'HOST_PIPE' );
if ( status <> 0 ) then
raise_application_error( -20001, 'Pipe error' );
end if;
end host;
I've granted the privileges to run dbms_pipe, BUT when i try to use it, it gets stuck while trying to run :
exec host('ls -l')
it doesn't respond....
then i tryed the part where it uses a shell to see what the procedure is doing, the code is:
#!/bin/csh -f
sqlplus tkyte/tkyte <<"EOF" | grep '^#' | sed 's/^.//' > tmp.csh
set serveroutput on
declare
status number;
command varchar2(255);
begin
status := dbms_pipe.receive_message( 'HOST_PIPE' );
if ( status <> 0 ) then
dbms_output.put_line( '#exit' );
else
dbms_pipe.unpack_message( command );
dbms_output.put_line( '##!/bin/csh -f' );
dbms_output.put_line( '#' || command );
dbms_output.put_line( '#exec host.csh' );
end if;
end;
spool off
"EOF"
chmod +x tmp.csh
exec tmp.csh
I supose it runs ok, becouse it creates a file named tmp.sch, but i can't really be sure becouse the previous part can't be done.
another question is that what does tom mean when he says "running this in the background", do i have to do it o does it do it itself.
what i need to do with this is send a file trough ftp, i've been using this shell named A-ftp.txt:
ftp -v -n 10.128.0.89 << EOF
user username password
bin
put "$1"
bye
EOF
where $1 is the name of the file. so when i try it trough my procedure it would be:
exec host('A-ftp.txt name-of-file')
but it olso gets stuck. I need this urgent!!!! what is the problem??? is there another solution to my problem?? is dbms_pipe the only way???
the code is the same as in the web page were i retrieved it, so i need to be given instructions in what to change and what to leave it as it is.
Restrictions:
I can only use pl/sql
I have little time
Thank You in advanceRestrictions:
I can only use pl/sql
I have little timeYou don't say which version of the database you are using. If it's 9.2 or higher you should check out Tim Hall's PL/SQL ftp implementation.
Cheers, APC -
Running a shell command in windows
Hi All,
I am facing trouble trying to run the unix command in windows. I know that Runtime.getRuntime().exec(command) has to be used for this purpose. I have a slightly different requirement , i.e it is not simply executing the command.
Before I execute a command say " export $KEY_SETTINGS " I need to invoke the mks shell and then execute a shell (which sets few variables).
So the code which is written (not working though :( ) is
osCommand = "export $KEY_SETTINGS "
pathMKS = "C:\\temp1\\mksnt\\mksnt\\sh.exe";
pathENV = "C:\\\\temp1\\\\temp2\\\\Environ.sh";
command[0] = "cmd";
command[1] = "/c";
command[2] = pathMKS + " -c " + "\". " + pathENV + " ; " + osCommand + "\"";
report.println("Comanda="+ command[0] + ' ' + command[1] + ' ' + command[2]);
Process process = Runtime.getRuntime().exec(command);
bufferedreader = new BufferedReader(new InputStreamReader(process.getInputStream()));
bufferedreaderErr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
for(int i = 0; (s = bufferedreader.readLine()) != null && i < 1; i++) {
commandOut = commandOut + s + "\n";
report.println("Print env:" + s);
while((s = bufferedreaderErr.readLine()) != null) {
commandErr = commandErr + s + "\n";
if (!commandErr.equals("")) {
throw new RuntimeException("Error running command: " + command[2] + "\n. Error: " + commandErr);
The error I am getting is
"Error running command: C:\oracle\mksnt\mksnt\sh.exe -c ". C:\\oracle\\appl\\Apps.sh ; export $KEY_SETTINGS "
Error: Export: not found.
Please help me out in this.
Best Regards
ShreyResending it again
-
How can i run oralce copy command with in sql j code [urgent]
I try it but it give me error inavalid sql command etc
i need help urgenthttp://www.oracle.com/technetwork/database/enterprise-edition/calling-shell-commands-from-plsql-1-1-129519.pdf
-
Excute Unix command Using PL SQL
Greeting,
how can I execute shell unix commands from PL SQL and without passing by the Java virtual machine, because my database server is not very performant to support the heaviness of Java.
Thank you for ur help!!!Is this what you need ?
TEST@db102 SQL> create table test(dir varchar2(100), url varchar2(200));
Table created.
TEST@db102 SQL> insert into test values('/tmp','http://otn.oracle.com');
1 row created.
TEST@db102 SQL> commit;
Commit complete.
TEST@db102 SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[ora102 work db102]$ cat /tmp/wget.sh
#!/bin/bash
rm -f /tmp/index.html
/usr/bin/wget -P $1 $2
[ora102 work db102]$ sqlplus test/test
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jul 29 17:11:28 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
TEST@db102 SQL> DECLARE
2 v_dir varchar2(100);
3 v_url varchar2(200);
4 BEGIN
5 select dir, url into v_dir, v_url
6 from test;
7 DBMS_SCHEDULER.CREATE_JOB(
8 job_name=>'testjob',
9 job_type=>'EXECUTABLE',
10 job_action=>'/tmp/wget.sh',
11 number_of_arguments => 2,
12 enabled => FALSE);
13 dbms_scheduler.set_job_argument_value('testjob',1,v_dir);
14 dbms_scheduler.set_job_argument_value('testjob',2,v_url);
15 dbms_scheduler.enable('testjob');
16* end;
TEST@db102 SQL> /
PL/SQL procedure successfully completed.
TEST@db102 SQL>sorry for lost indentations, but tags do not help us these days.... -
Running a shell command when UPS power is active.
I am hoping someone can help me create a shell command that will execute an automator workflow to send an email when my server has switched to UPS power.
I've created an automator workflow that opens mail, creates an email, and sends it. Now I need to create a way to execute the workflow when the server switches from AC power to UPS power.
Is this whole setup even possible? I have never written apple shell commands before so that is where I need the most help.
Thanks!Resending it again
-
Running MS-DOS commands using Runtime.exec()
Is there any way to run the dos commands like copy and del from our java program? Actually I want to implement a visual console kind of thing and have to transfer the commands to the prompt and get the result string that is to be displayed in a JTextArea?
Please help me. It'll be very nice of you...thanksI can help you in two ways:
o by telling you to run cmd.exe and pass the rest as parameters.
o by pointing out this is the wrong forum for you equestion. -
Runnings Shell Commands in PL/SQL Procedure
Hi folks,
I want to run the SQL/Plus HOST command within an PL/SQL Procedure.
I tried it with "EXECUTE IMMEDIATE 'HOST ls -la';"
and I'm afraid, that it didn't work.
Has anyone of you a suggestion?
regards
Markusyou can use system library.
Example for UNIX:
<<< create library in DB >>>
SQL>create or replace library libc
as
'/lib/libc.so';
<<< create procedure >>>
SQL>create or replace function libc_system (
cmd_str in varchar2
) return pls_integer
as external
library libc
name "system"
language c
parameters (cmd_str string);
<<< use it! >>>
SQL>exec libc_system('/usr/bin/cp /home/myhome/thefile /export/myfiles/thefile1);
NOTE1: You are need to be a familiar with "extproc" feature...
NOTE2: sometime(or always) you are need to put full path to executable files, like: "/usr/bin/cp"
I didn't checked a usage of env variables, like: $HOME, $ORACLE_HOME, etc...
NOTE3: This way can't be used to return a "screen" info from the function, like: "cat file1.txt | grep SOMETHING ".
For this case you can use utl_file package, like: "cat file1.txt | grep SOMETHING > file2". After that you can use utl_file package to read file2...
null -
Error when run UNIX Shell Script from PL/SQL
when I run command.
I got the error message, please anyone suggest me., what's problem?
thanks in advance.
modd
exec shell('ls')
ORA-06520: PL/SQL: Error loading external library
ORA-06522: '/modd/test/shell.so' is not a valid load module: Bad magic number
ORA-06512: at "modd.SHELL", line 0
ORA-06512: at line 1Hi
Try to add
(ENVS=EXTPROC_DLLS=ANY) to listener.ora
eg:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /oracle/product/9.2)
(ENVS=EXTPROC_DLLS=ANY)
(PROGRAM = extproc)
lajos -
Error while Executing Unix Shell Commands Using Runtime clas
I am trying to run the following code in java on unix machine to execute cat command.
Runtime runtime = Runtime.getRuntime();
try {
System.out.println("before catexecute");
Process process = runtime.exec("cat /export/home/shankerr/local.profile > /export/home/shankerr/local1.txt");
try {
if (process.waitFor() != 0) {
System.err.println("exit value = " +
process.exitValue());
catch (InterruptedException e) {
System.err.println(e);
But i get the following error on the console
exit value = 2
cat: cannot open >
cat: cannot open /export/home/shankerr/local1.txt
The same command if i run on unix console directly it creates a new file and copies the content into the new file local1.txt
kindly help me on the sameThe redirection operator > along with stuff like pipe | history !$ etc. is interpreted by the shell, not by the cat program.
When you do cat X > Ycat only sees the X. The rest is interpreted by the shell to redirect the cat program's stdout.
However, when you Runtime.exec(), you don't have the shell, so cat sees X > Y as its arguments, and interprets them all as file names. Since there's no file named > you get the error.
The solution is to first man cat on your system and see if it happens to have a -o or somesuch operator that lets it (rather than the shell) send its output to a file. If not, then you need to invoke a shell, and pass it cat and all of cat's args as the command to execute.
Read the man pages for you shell of choice, but for bash, I believe you'd give Runtime.exec() something like /bin/bash -c 'cat X > Y' -
Operating system Cammand such as UNIX command using PL/SQL
Hi All,
I am using forms 4.5 using oracle financials 10.7 and I want to execute an operating system file such as move on server side. I am able to do it on client side using host command but cannot figure out how I can use it on server side. I am using following version of oracle:
Oracle8i Enterprise Edition Release 8.1.7.3.0 - 64bit Production
PL/SQL Release 8.1.7.3.0 - Production
CORE 8.1.7.0.0 Production
TNS for HPUX: Version 8.1.7.3.0 - Production
NLSRTL Version 3.4.1.0.0 - Production
Thanks
AqilIf I dont have java support is there no way to solove this problem?Steven Feuerstein provides some simple example here
http://apex.oracle.com/pls/otn/f?p=2853:4:12114297745467903505::NO::P4_QA_ID:3202 -
Running a OS command from PL/sql Block.
I am using UTL_FILE to write data to a text file from within a stored procedure.Before terminating the procedure i would like to run FTP command on the server to copy the file to a different server. Can this be done..... ? Or is this asking for too much..
nullSearch the forums for 'external procedure'. There are examples that have been posted in the past few weeks.
null -
Run An OS Command Using Java?
I want to write a java class that does some Unix system maintenance. In particular, I want to read some data out of a database and then do some calculations to figure out which files in particular can be tarred and zipped. The database part is already handled (in other words, I can identify the files I want to take action on) but I'm not sure how to run an operating system command (e.g. "tar cvzf myfile file1 file2 file3") using java.
Read this:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
%
Maybe you are looking for
-
Blank white pages in Safari (until Firefox opens them)
Occasionally, pages will come up blank in Safari. (View source is also blank.) These are pages that have worked fine in the past, and they are simple HTML, with no JavaScript, etc. Refreshing and deleting history do not help. What does help is openin
-
Java is not working. Already tried downloading Java 7 update. Java (Oracle) cannot verify that I have Java installed. Java does not show up in system prefrences even after download success screen, and shutting down all apps and computer. I checked co
-
SQLPlus login hangs because of "Thread 1 cannot allocate new log"
Hi to everybody! Could you please give an advice how to overcome the following situation. In my 10GR2 database I have destination for archive logs placed in ASM disk group. When suddenly this disk group becomes overfilled I can not login into the dat
-
Hi all,i have a requirement in which i have to show user in select one choice only few values and also the value against that field as selected value select one choice.LOV does not contain the value submitted against the field in drop down list.Can i
-
HT204053 I lost my iphone how can i find it?
My phone is ********** i cant find it <Personal Information Edited by Host>