troubleshooting Question

How can I automate this UNIX script

Avatar of toooki
toooki asked on
Unix OSLinuxOracle Database
13 Comments2 Solutions740 ViewsLast Modified:
I want to automate the following commands so that I could run it as a cronjob on my Solaris10 server:

I have a source directory :
/var/www/temp1/
The files are like
1356652700.file1.dat.bz2.cor
1356652700.file2.dat.bz2.cor
1356652700.file3.dat.bz2.cor

I know the file name part except for the timestamp part (1356652700). Each time the cron is run, the timestamp part of the set of files will be different. In the next run I will probably have these in the source: 1356658200.file1.dat.bz2.cor , 1356658200.file2.dat.bz2.cor and 1356658200.file1.dat.bz2.cor.

So I do:

#!/bin/sh
DIR1=/var/www/temp1/
DIR2=/var/www/process/

Now I manually run:
$cd /var/www/process/
$mv 1356652700.file1.dat.bz2.cor 1356652700.file1.dat.bz2
$mv 1356652700.file2.dat.bz2.cor 1356652700.file2.dat.bz2
$mv 1356652700.file3.dat.bz2.cor 1356652700.file3.dat.bz2
$bzip2 -dc 1356652700.file1.dat.bz2 > 1356652700.file1.dat
$bzip2 -dc 1356652700.file2.dat.bz2 > 1356652700.file2.dat
$bzip2 -dc 1356652700.file3.dat.bz2 > 1356652700.file3.dat
$rm *.bz2
$mv 1356652700.file1.dat tab1.dat
$mv 1356652700.file2.dat tab2.dat
$mv 1356652700.file2.dat tab3.dat
$./my_cron.cron
$sqlplus mylogin/mypwd@myserver.com/SOMETHING <<ENDOFSQL
create or replace procedure my_prod as
begin
  declare
    db_package.db_proc1('1356652700.file1.dat');
    db_package.db_proc2('1356652700.file2.dat');
    db_package.db_proc2('1356652700.file3.dat');
  end;
end load_con;
exec DBMS_SCHEDULER.RUN_JOB('MY_JOB', FALSE);
exit;
ENDOFSQL
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros