Ftp in unix shell script
hi.
I have the following requirement to be written as a shell script.
1. ftp to another server ( say x)
2. change the directory ( cd /data)
3. check if there exists a file with extention .csv. If it does,
3.1 get the file and copy it to a backup directory,
3.2 rename the file to test.csv
3.3 login to an oracle schema and execute a procedure.
3.4. Based on the output, echo success or error
3.5 If success delete the file
Can all this be done in one script. ?
Any help would be highly appreciated.
Thanx
Hi ,
Hope the folllowing scipt listing will help you.
cd /u01/backup/
ftp -in << EOF
open x
cd data
ls . /u01/backup/test.out
EOF
# Check whether .csv file exists.
cat /u01/backup/test.out | awk '{print $9}' | tail +2 | cut -d "." -f 2 | grep csv
if [ $? -eq 0 ]
then
cd /u01/backup/
ftp -in << EOF
open x
cd data
get
EOF
fi
# renaming file
cd /u01/backup/
mv *.csv test.csv
# set environment for database running
export ORACLE_HOME=
$ORACLE_HOME/sqlplus/bin -s /nolog << EOF > /dev/null
connect user/pass
spool output.lst
@execute_the_script.sql
spool off
EOF
## procees output.lst and echo the result.
## Execute further steps..
Regards,
Aditya.
Similar Messages
-
How to prepare for Converting UNIX shell scripts to PL/SQL
Hi All
I was said, that i may have to convert a lot of unix shell script to PL/SQL, what are the concepts i need to know to do it efficently,
what are the options PL/SQL is having to best do that.
I know the question is little unclear, but I too dont have much inputs about that i'm sorry for that, just its a question of how
to prepare myself to do it the best way. What are the concepts i have to be familiar with.
Many Thanks
MJJust how much work is involved, is hard to say. Many years ago I also wrote (more than once) a complete ETL system using a combination of shell scripts, SQL*Plus and PL/SQL.
If the PL/SQL code is fairly clean, uses bind variables and not substitution variables, then it should be relatively easy to convert that PL/SQL code in the script to a formal stored procedure in the database.
There is however bits and pieces that will be difficult to move into the PL/SQL layer as it requires new software - like for example FTP'ing a file from the production server to the ETL server. This can be done using external o/s calls from within PL/SQL. Or, you can install a FTP API library in PL/SQL and FTP that file directly into a CLOB and parse and process the CLOB.
Think of Oracle as an o/s in its own right. In Oracle we have a mail client, a web browser, IPC methods like pipes and messages queues, cron, file systems, web servers and services, etc. And PL/SQL is the "shell scripting" (times a thousand) language of this Oracle o/s .
In some cases you will find it fairly easy to map a Unix o/s feature or command to one in Oracle. For example, a Unix wget to fetch a HTML CSV file can easily be replaced in Oracle using a UTL_HTTP call.
On the other hand, techniques used in Unix like creating a pipe to process data, grep for certain stuff and awk certain tokens for sed to process further... in Oracle this will look and work a lot different and use SQL. -
Calling UNIX shell script from ODI package?
Hi,
How Can we call UNIX shell script from ODI package?
I have a ftp_ss.sh script which which ftps a file from remote server to local server, archives the last file and renames new file to the standard (ie file data store)name.
I want to run the above script and interfaces from a package.
Any help is greately appreciated.
Thanks,
RDIn the package window, put "OS Command" from the toolbox.
Provide the command parameters to this tool in form of "/path/to/script/ftp_ss.sh" -
Fle import the unix shell script
hi all
I want to develop unix shell script & cron job to read ftp file and call an oracle procedure to import the data in an oracle database
can any one tell me how to go about it ?
also does any one have some documentation related to the topic
plzzz help me
mandarHi,
I want to develop unix shell script & cron job to read ftp file and call
an oracle procedure to import the data in an oracle databaseYou can
1/ use ftp to get the file to Oracle Instance host then call a Proc/Package that'll parse the file.
2/ write/find on google a FTP package using UTL_TCP then create a procedure using the package to open the ftp file and parse it.
You don't give much details on what the actual aim is, si I can't be more specific.
can any one tell me how to go about it ?There might be other possibilities, describe what you want to achieve globally and we'll give you more advices.
also does any one have some documentation related to the topicTahiti: http://tahiti.oracle.com
maybe AskTom: http://asktom.oracle.com
Regards,
Yoann. -
Calling a report from unix shell script
Hi,
I had to call a report from unix shell script.
May i know the procedure to accomplish this
Thanks in Advance
A.GopalFirst you should not include the whole path to your report in the call ...
Use like this:
/ora/u01/oracle/v101/as2/bin/rwrun.sh report=an_stati destype=file desname=/ora/u01/oracle/v101/as2/test.pdf desformat=pdf
In $ORACLE_HOME/bin/reports.sh:
1) Verify that you have updated the REPORTS_PATH variable to include your folder where you have the report in question
REPORTS_PATH=/ora/u20/app/qits/env1/run:$ORACLE_HOME/reports/templates:$ORACLE_HOME/reports/samples/demo: ....
2) Verify that the REPORTS_TMP variable is pointing to a valid location and that the oracle user has access to write on it.
After that, post the content of the tracefile located at $ORACLE_HOME/reports/logs/{in-process report server name folder}/rwserver.trc
If no file is present then it means that you need to enable trace in your reports's conf file.... go to the $ORACLE_HOME/reports/conf folder and and locate the .conf file that correspond to your in-process reports server name (as specified in the rwservelet.properties file)... open/edit the file to enable trace logs ..
i.e.
Change the following line:
<!--trace traceOpts="trace_all"/-->
to <trace traceOpts="trace_all"/>
Bounce the reports server and try to run the report again, this time the .trc file should be generated, post the content so that we can take a look. -
How can i call a Stored Procedure procedure from Unix shell script
Hi All,
I want to call a Strored PL-SQL Procedure through Unix shell script.
Can any body help me with this.
Regards,
SaurabhI prefer a seperate script like the other poster mentioned. However, most shells can use a 'here' document as well ...
sqlplus uid/pwd <<END
exec myproc
exit
ENDRichard -
Error while trying to execute a unix shell script from java program
Hi
I have written a program to execute a unix shell script in a remote machine. I am using J2ssh libraries to estabilish the session connection with the remote box.The program is successfully able to connect and authenticate with the box.
The runtime .exec() is been implemented to execute the shell script.I have given below the code snippet.
try {
File file_location = new File("/usr/bin/");
String file_location1 = "/opt/app/Hyperion/scripts/daily";
String a_mib_name = "test.sh";
String cmd[] = new String[] {"/usr/bin/bash", file_location1, a_mib_name};
Runtime rtime = Runtime.getRuntime();
Process p = rtime.exec(cmd, null, file_location);
System.out.println( "Connected to the server1" );
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = br.readLine();
while(line !=null)
System.out.println(line);
line = br.readLine();
br.close();
p.getErrorStream ().close ();
p.getOutputStream().close();
int retVal = p.waitFor();
System.out.println("wait " + retVal);
//session.executeCommand("ls");
catch (IOException ex) {
I get an error message
Connected to the server
java.io.IOException: Cannot run program "/usr/bin/bash" (in directory "\usr\bin"
): CreateProcess error=3, The system cannot find the path specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at SftpConnect.main(SftpConnect.java:143)
Caused by: java.io.IOException: CreateProcess error=3, The system cannot find th
e path specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
I am sure of the file path where the bash.sh and test.sh are located.
Am i missing something? Any help would be greatly appreciated.
Thanks
SenthilHi, I am using a simple program to connect to a RMI server and execute shell script. I use the Runtime.exec aommand to do the same.
The script is sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul
The script when run from the server, gives no errors. But when ran using rthe above method in java, gives errors as follows,
Mycode:
String command = "/bin/sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);
int exitVal = proc.exitValue();
System.out.println("Process exitValue: " + exitVal);
java.io.IOException: CreateProcess: /bin/sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul error=3
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at DecryptTest.main(DecryptTest.java:18)
Can anyone please help -
Error while executing unix shell script from java program
Hi All,
I am trying to execute unix shell script from a java program using Runtime.execute() method by passing script name and additional arguments.
Code snippet :
Java Class :
try{
String fileName ="test.ksh";
String argValue ="satish"; // value passed to the script
String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
Process proc = Runtime.getRuntime().exec(exeParam);
int exitValue = proc.waitFor();
sop("Exit Value is : "+exitValue);
catch(Exception e)
e.printStackTrace();
}Test.ksh
export -- application realated paths..
nohup abc.exe 1> test.log 2>&1;
$1
exit.By running the above java class , i am getting exit Value: 139 and log file test.log of 0 bytes.
when i am running the same command (/usr/bin/ksh test.ksh satish) manually, it's calling abc.exe file successfully
and able generate the logs properly.
Pls let us know where exactly i am stuck..
Thanks in advance,
Regards,
SatishHi Sabre,
As per the guidelines provided by the article, i had done below changes..
InputStream is = null;
InputStreamReader iStreamReader = null;
BufferedReader bReader = null;
String line = null;
try{
String fileName ="test.ksh";
String argValue ="satish"; // value passed to the script
String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
Process proc = Runtime.getRuntime().exec(exeParam);
is = proc.getErrorStream();
iStreamReader = new InputStreamReader(is);
bReader = new BufferedReader(iStreamReader);
System.out.println("<ERROR>");
while((line = bReader.readLine()) != null)
System.out.println("Error is : "+line);
System.out.println("</ERROR>");
int exitValue = proc.waitFor();
sop("Exit Value is : "+exitValue);
catch(Exception e)
e.printStackTrace();
Now , it's showing something like..
<ERROR>
</ERROR> -
Need Help in creating Unix Shell Script for database
Would be appreciable if some one can help in creating unix shell script for the Oracle DB 10,11g.
Here is the condition which i want to implement.
1. Create shell script to create the database with 10GB TB SPACE and 3 groups of redo log file(Each 300MB).
2. Increase size of redolog file.
3. Load sample schema.
4. dump the schema.
5. Create empty db (Script should check if db already exists and drop it in this case).
6. Create backup using rman.
7. restore backup which you have backed up.This isn't much of a "code-sharing" site but a "knowledge-sharing" site. Code posted me may be from a questioner who has a problem / issue / error with his code. But we don't generally see people writing entire scripts as responses to such questions as yours. There may be other sites where you can get coding done "for free".
What you could do is to write some of the code and test it and, if and when it fails / errors, post it for members to make suggestions.
But the expectation here is for you to write your own code.
Hemant K Chitale -
Reg: UNIX shell script at File Adapter
Hi all,
I am doing a File to file scenario and using command line arguments in Sending file adapter. I am using UNIX shell script ".sh" file for executing the command.
I gave the following path at "Run OS command before message processing" parameter:
/temp/xidelivery/send/FILOSC004_shell.sh
and this file contains following code:
<b>#!/user/bin/sh cp /temp/xidelivery/send/FILOSC004_in.txt /temp/xidelivery/send/FILOSC004_input_copy4.txt</b>
I put the source file, FILOSC004_in.txt and shell script files at the respective paths.
If I give "cp" command directly in command line it is working fine. But I could not execute this with shell script. Can any body give me the reason where I gone wrong.
Regards,
Pavani.Hi,
can you try this,
bash /temp/xidelivery/send/FILOSC004_shell.sh
let me know.
hey you can check the blog below to catch the OS errors,
/people/michal.krawczyk2/blog/2005/08/17/xi-operation-system-command--error-catching
Prasad Babu.
Message was edited by:
PrasadBabu Koribilli -
Sending email attachments using unix shell script
hi
I want to send report generated my spooled file as attachment using unix shell script.
Can somebody help me out ?
many thanksthanks a tonn it worked.
but i have another issue is it possible to add names in CC also ?
Also here is my code which spools the output of SP to a txt file. the File name is generated dynamically.
as shown below:
I need to send this generated file as attachement.
how do I do this? Here the shell script
=========================================================
#!/bin/sh
ORA_USER=scott
ORA_PWD=tiger
#Get the input parameter
if [ ! "$1" ]; then
STR="NULL"
else
STR="'"$1"'"
fi
#echo "exec pkg1($STR);"
#Connecting to oracle
sqlplus -s <<EOF
$ORA_USER/$[email protected]
---sql plus enviornment settings
set linesize 160
set pagesize 60
set serveroutput on size 1000000 for wra
set feedback off
set termout off
column dcol new_value mydate noprint
select to_char(sysdate,'YYYYMMDDHH24MISS') dcol from dual;
spool &mydate.report.txt
exec pkg1($STR);
spool off
EOF
exit
=========================================================
the file name will take sysdate as name so that every time a new file will be generated.
this file I need to send as attachment.
null -
Calling stored procedure from unix shell script
Hello,
I am facing a problem while calling a stored procedure from UNIX shell script. I want to return a output variable from the stored procedure to the UNIX environment.
Here is the code-
#!/bin/sh
OUTPUT=`sqlplus cmag/magnum@dw <<ENDOFSQL
set serveroutput on;
var prd_out varchar2(100);
exec create_pm_window(:prd_out);
exit;
ENDOFSQL`
echo " output is - $OUTPUT"
The problem is :prd_out is not getting copied to shell variable OUTPUT.
I have a dbms_output.put_line in the stored proc create_pm_window and I can see that prd_out is getting populated.
Any help is really appreciated.
Thanks'
RakheeFirst step :
make sure the PL/SQL works as expected.
Does the following display the expected output executed from SQL*Plus ?
set serverout on
declare
prd_out varchar2(100);
begin
create_pm_window(prd_out);
dbms_output.put_line('output is '||prd_out);
end;
I don't have your procedure, but using a dummy procedure like :
Scott@my10g SQL>create procedure foo(p_out in out varchar2)
2 is
3 begin
4 select 'Hello '||instance_name into p_out from v$instance;
5 end;
6 /
Procedure created. and a toto.sh script as :OUTPUT=`sqlplus -s scott/tiger <<EOF
set pages 0 lines 120 trimout on trimspool on tab off echo off verify off feed off serverout on
var mavar varchar2(100);
exec foo(:mavar);
print mavar;
exit;
EOF`
echo "OUT = ${OUTPUT}"
exitIt works fine :[oracle@Nicosa-oel ~]$ ./toto.sh
OUT = Hello my10g -
Please provide me unix shell script (export and import of database schema)
please i am new in unix
\please give me sample unix shell script (export and import of database schema)please i am new in unix
\please give me sample unix shell script (export and import of database schema)Instead of providing you the readymade unix shell script for your requirement, I will give you the hints to prepare the same at your own.
Create a file with .sh extension.
# Specify and set all required Environment variables.
ORACLE_HOME, PATH, NLS_LANG, etc.,
# Use the export command with all clauses
export scott/tiger@orcl file=scott.dmp log=scott_emp.log
# Compress it.
compress scott.dmp
Refer any unix/linux documents for scripting basics.
http://www.bijoos.com/ora7/oracle_unix.htm
Regards,
Sabdar Syed. -
Unable to pass parameter in oracle procedure through unix shell script
Hi Experts,
I have oracle procedure where in I have to pass the value of procedure parameter through unix script.
Follwoing is the sample procedure which i tried to exceute from the unix.
Procedure:
create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) AS
sql_stmt varchar2(1000) := NULL;
v_count number := 0;
v_owner varchar2(100) := owner;
begin
sql_stmt:='select count(1) from '||v_owner||'.EMP@infodb where rownum<=10';
execute immediate sql_stmt into v_count;
DBMS_OUTPUT.PUT_LINE(sql_stmt);
DBMS_OUTPUT.PUT_LINE(v_count);
END;The script which I used is:
Unix
#!/bin/ksh
parm=$1
echo start
sqlplus -s scott@DEV/tiger <<EOF >>result_1.txt
set serveroutput on;
select '$parm' from dual;
exec owner.PRC_TESTING_OWNER('$parm');
EOFThe script is working fine that is i am able to pass to parameter value through unix shell script. :)
But if I want to pass the value of the owner in cursor , I am unable to pass this value through unix.
Following the procedure which i am trying to implement.
create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) IS
v_owner varchar2(100) := owner;
CURSOR main_cur IS
select
i.ROWID rid ,
emp_name,
deptid
from v_owner.employee;
CURSOR subset_cur(c_deptid NUMBER ) IS
SELECT *
FROM v_owner.DEPT d
where d.dept_id=c_deptid;
--##main loop
FOR i IN main_cur LOOP
FOR j IN subset_cur(i.deptid) LOOP
BEGIN
insert into v_owner.RESULT_TABLE
END;
END LOOP;
END LOOP;How can i pass parameter value of the stored procedure through unix script(that is "owner" in this case), when these parameter value is
used in cursor? :(
Can anybody help me regarding the same?
Thanks in Advance !! :DIt's not the parameter in the cursor that is the problem, it's that you are trying to use static SQL for something that won't be known until run time (the owner of the table).
You would need to use something like ...
declare
l_owner varchar2(30) := 'SCOTT';
l_ref_cursor sys_refcursor;
type l_ename_tab is table of scott.emp.ename%type;
l_ename_array l_ename_tab;
begin
open l_ref_cursor for
'select ename
from ' || l_owner || '.emp';
loop
fetch l_ref_cursor bulk collect into l_ename_array limit 10;
exit when l_ename_array.COUNT = 0;
for x in 1 .. l_ename_array.count
loop
dbms_output.put_line(l_ename_array(x));
end loop;
end loop;
close l_ref_cursor;
end;
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01 -
i have a doubt as to how to comment a line in a shell script as i have to do that in a config. file of Oracle 9i Application Server. Is it a "--" in a line. Please help.
regardsTry to use # as a comment in unix shell script.
The config files in Oracle AS are xml based so the comment
therefore is
<!-- This is a comment -->
Hope that helps.
Maybe you are looking for
-
Burning VIDEO_TS to DVD
Hello all, I have a VIDEO_TS folder from a DVD. Legal, of course...well, anyway, I'd like to burn it to a new blank DVD to make a disc compatible with any DVD player, not just a Mac/Windows computer. I actually tried it with Disco (www.discoapp.com)
-
Conditional text and table numbers
I have a source doc from which I am going to generate two user guides (I am new at this). I have two conditional tags set, which I plan to show/hide as required to generate the final PDFs. First snag: I have a products specification table, which is d
-
IPhoto can't access photo library
I recently updated iPhoto. Now it can't access my photo library. How do I fix this?
-
Another HP user with audio problem (dv6119us)
I'm not holding my breath for a solution, since HP seems to not care. I have a DV6119us that came with XP but is listed as "Vista Compatable". HP even sent me a spiffy new disk of Vista. Since installing Vista, I do not get sound from my speakers. Th
-
Knowledge Management & Collaboration
Hi Friend, I am not a portal expert but I have to support some of the portal tasks from a person who is on a vacation. In Development portal, I have required role and group assigned to my user and I can see the u2018Edit Pageu2019 option to edit the