If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > shell script for copying

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-09-10, 05:45
paddu paddu is offline
Registered User
 
Join Date: Aug 2010
Posts: 6
shell script for copying

Hi,

I just need a shell script that copies a list of files from a directory in a remote server to my current directory at local server

the remote server may contain the following list:
/root/pradeep/myfiles/default
/root/pradeep/myfiles/dir1
/root/pradeep/myfiles/dir2
...
/root/pradeep/myfiles/dir10

the following are the conditions:
1) the mandatory parameters to the script are <server name> < userid> < password>

if this is given it should copy all the file in a directory /root/pradeep/myfiles/default
to my local system

2) if the fourth option is mentioned, that should be any directory name in /root/pradeep/myfiles/
the script should copies all the files in that directory
to my current directory

thanking you in advance
Reply With Quote
  #2 (permalink)  
Old 08-09-10, 07:20
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,452
That could be easily accomplished by scp: it accepts server-side wildcards.
Reply With Quote
  #3 (permalink)  
Old 08-09-10, 08:00
paddu paddu is offline
Registered User
 
Join Date: Aug 2010
Posts: 6
Hai,
Im a new user in this environment...could u kindly provide with the entire script
Reply With Quote
  #4 (permalink)  
Old 08-09-10, 11:32
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Thumbs down Homework?

Quote:
Originally Posted by paddu View Post
Hai,
Im a new user in this environment...could u kindly provide with the entire script
Could you kindly try and do your homework on your own.
I you do get stuck, we may be able to guide you.
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #5 (permalink)  
Old 08-09-10, 12:16
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Quote:
Originally Posted by n_i View Post
That could be easily accomplished by scp: it accepts server-side wildcards.
I would have used uucp
Reply With Quote
  #6 (permalink)  
Old 08-09-10, 23:56
paddu paddu is offline
Registered User
 
Join Date: Aug 2010
Posts: 6
Yaah!!!! i tried the following script... but problem is 'if-condition' are not supported in the FTP script what i had used.... could someone help me

#!/bin/bash
##
##Script to load FILES


if [ $# -lt 3 -a $# -gt 4 ] ; then
echo "please enter the command properly"
echo " "
echo "Usage: <Script_name><server><user_name><password>[<directory name>]"
echo "example: sh pradeep.sh server1 root root123 [dir1]"
echo "try again"

elif [ $# -eq 3 ] ; then
hostname=$1
username=$2
password=$3

ftp -n -i $hostname <<END_SCRIPT
quote USER $username
quote PASS $password
bin
cd /root/pradeep/myfiles/default
mget *.rpm
END_SCRIPT
elif [ $# -eq 4 ] ; then
hostname=$1
username=$2
password=$3


ftp -n -i $hostname <<END_SCRIPT
quote USER $username
quote PASS $password
bin

cd /root/pradeep/myfiles
ls -l | grep "$4" > /temp/available.$$

temps =`cat /temp/available.$$`

if [ " $temps " == "" ] ; then
cd /root/pradeep/myfiles/$4
mget *.rpm
else
echo "Sorry the required file doesnt exit's"
fi
END_SCRIPT

fi
Reply With Quote
  #7 (permalink)  
Old 08-10-10, 08:42
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

Try this:
Code:
#!/bin/bash
##
##Script to load FILES
if [ $# -lt 3 -a $# -gt 4 ] ; then
  echo "please enter the command properly"
  echo " "
  echo "Usage: <Script_name><server><user_name><password>[<directory name>]"
  echo "example: sh pradeep.sh server1 root root123 [dir1]"
  echo "try again"
  exit 1
fi
hostname=$1
username=$2
password=$3
dirname=$4
dirname=${dirname:-'default'}
logname=ftp_`date +%Y\-%m\-%d`.log
ftp -n -i $hostname <<END_SCRIPT >$logname
quote USER $username
quote PASS $password
bin
cd /root/pradeep/myfiles/$dirname
mget *.rpm
bye
END_SCRIPT

rc==$(grep ' not found.' $logname|wc -l)
if [ $rc -gt 0 ] 
then
  echo "Sorry the required file doesn't exist."
  exit 2
fi
exit 0
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #8 (permalink)  
Old 08-11-10, 01:39
paddu paddu is offline
Registered User
 
Join Date: Aug 2010
Posts: 6
Thanks

Thanks u every much for the reply,

but, in the script, the statement
ftp -n -i $hostname <<END_SCRIPT >$logname

the variable logname
which is intended to track whether the files is there are not( i suppose) , is not working...no error ... and no output is shown...

could u kindly once again see the script and modify it please
Reply With Quote
  #9 (permalink)  
Old 08-11-10, 06:52
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
The output is in a file named "ftp_2010-08-11.log", however there should be quotation marks around the "picture string"|"output format" in the date command.
Reply With Quote
  #10 (permalink)  
Old 08-11-10, 07:38
paddu paddu is offline
Registered User
 
Join Date: Aug 2010
Posts: 6
@kitman

I couldnt get u sir
Reply With Quote
  #11 (permalink)  
Old 08-11-10, 08:25
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
quoted string...

Quote:
Originally Posted by paddu View Post
I couldnt get u sir
What he means is to add quotes like this:
Code:
# -- Etc ...
logname="ftp_`date +%Y\-%m\-%d`.log"
ftp .....-- Etc ...
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On