Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Unix Shell Scripting Copy from one unix server to another

Posted on 2011-03-02
19
Medium Priority
?
1,711 Views
Last Modified: 2012-05-11
I need a shell script which can copy the files from one unix server to another after a exp command is executed successfully and remove the file from the source server.
(exp is a utility in oracle which exports table as dump files, I am sure most of you guys know, but just in case)
for ex: (psuedo code)

exp USERID=usr/pwd TABLES= table_a:sub_part_2002_A FILE=/source/path/dump_area/sub_part_2002_A .dmp

copy "sub_part_2002_A .dmp" to the "/remote/path/dump_area"

After succesful copy it should delete the file from the source path (/source/path/dump_area/sub_part_2002_A .dmp)

----
Also one more thing to this is:
I have a file which has following content:
---
sub_part_2002_A .dmp
sub_part_2002_J .dmp
sub_part_2002_U .dmp
sub_part_2002_R .dmp
sub_part_2002_D .dmp
sub_part_2002_E .dmp
sub_part_2002_M .dmp
sub_part_2002_S .dmp
..........
sub_part_2002_A in the exp command should be taken from this file. After this is done then it should goto the next line of the file and replace it with sub_part_2002_J .dmp in the exp command. You see where I am going?

Thanks@
0
Comment
Question by:D-pk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
  • 2
  • +1
19 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35023235
There are a few options but they depend on how your unix shop is set up.

Can you run: rcp, ftp, remsh, ???
0
 

Author Comment

by:D-pk
ID: 35023246
I can ftp
0
 
LVL 3

Expert Comment

by:saranyannarayanan
ID: 35023250
rsync also is a good solutiion
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 19

Expert Comment

by:jools
ID: 35023252
scp/sftp would be an ideal candidate for this... but as slightwv pointed out, it depends on your setup.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35023261
If you can ftp, then what do you need help with?

Seems like a pretty simple shell script.
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 total points
ID: 35023266
There are a ton of links on how to FTP from a shell script.

Here's the first:
http://www.stratigery.com/scripting.ftp.html
0
 

Author Comment

by:D-pk
ID: 35023267
I need a sample script to work with.. I am very new to shell scripting...
0
 

Author Comment

by:D-pk
ID: 35023512
In the above link's example, where should I give the source file name and its path.

Ex:


#!/bin/sh
HOST='198.xx.xxx.xx'
USER='remoteuserid'
PASSWD='remotepasswd'
FILE='/remote/server/path/file.txt'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35023518
The variable:
FILE='/remote/server/path/file.txt'
0
 

Author Comment

by:D-pk
ID: 35023532
if that is the source, where should I give the destination path (Remote server path)
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35023533
The other thing you need to make sure of is putting ftp in 'binary' mode.

I have no way to test it but right above the 'put' line add: bin

...
Bin
Put $FILE
...

0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35023549
My ftp is rusty but that is the file you are 'putting' on the remote server.

If you need a specific remote dir, try a cd command above the 'put'

As I mentioned, there's a lot of info out there on basic unix commands.  I just posted the first link I came across.

I would suggest you familiarize yourself with any commands you receive here to ensure they don't lead you down the wrong path.
0
 
LVL 3

Expert Comment

by:saranyannarayanan
ID: 35023809
rsync should be good too
http://ss64.com/bash/rsync.html


0
 

Author Comment

by:D-pk
ID: 35024387
I tried this script and it gave me this error:
FTP Connection refused.. I am trying to fix this error to see if ftp is installed or not..
But, I want some suggestions with this script,
I want to make sure the file is copied to the destination server and only after that it should be deleted from my local server...
Please advise...
Thanks@

#!/bin/ksh
file="/local/server/dump_fldr/test.txt"
# while loop
while read line
do
exp USERID=usr/pwd TABLES= table_a:$line FILE=/local/server/dump_fldr/$line.dmp
tmp_file=/local/server/dump_fldr/test2.txt
#file_nm=$line.dmp
ftp -nv <<EOF > ${tmp_file}
    open 154.xx.xx.xx
    user remoteuser remotepwd
    binary
    lcd /local/server/dump_fldr/
    cd /remote/server/dump_fldr/    
    put $line.dmp  
    rm $line.dmp 
EOF

done <"$file"

Open in new window

0
 

Author Comment

by:D-pk
ID: 35024403
my test.txt file contains the list of file names i need to copy...
for ex:
sub_par_2007_a
sub_par_2007_g
sub_par_2007_s
sub_par_2007_y
sub_par_2007_l
.....
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35026707
Did you manually try those ftp parameters on a single file from the command prompt to make sure the ip address, user and password are correct?

I don't have access to UNIX right now so I cannot help debug the script you posted but everything looks like it should work.

Hopefully one of the other Experts can see if there's a flaw in the script that I'm missing.
0
 

Author Comment

by:D-pk
ID: 35047606
One final question...
will the if condition is the correct one to check whether the prev command was successful?

Thanks@
#!/bin/ksh
file="/local/server/dump_fldr/test.txt"
# while loop
while read line
do
exp USERID=usr/pwd TABLES= table_a:$line 

if [ $? -eq 0 ];then
 
ftp -nv <<EOF 
    open 154.xx.xx.xx
    user remoteuser remotepwd
    binary
    lcd /local/server/dump_fldr/
    cd /remote/server/dump_fldr/    
    put $line.dmp  
    rm $line.dmp 
else 
exit;
fi
EOF

done <"$file"

Open in new window

0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35048322
I'm not sure what return values exp returns.  I suggest you refer to the online docs for the valid return codes.

As far as the syntax, it looks good if exp follows typical unix coding standards.
0
 

Author Closing Comment

by:D-pk
ID: 35048351
Thanks everyone for their inputs..
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question