Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2010
    Posts
    6

    Unanswered: 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

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    That could be easily accomplished by scp: it accepts server-side wildcards.

  3. #3
    Join Date
    Aug 2010
    Posts
    6
    Hai,
    Im a new user in this environment...could u kindly provide with the entire script

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    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

  5. #5
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    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

  6. #6
    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

  7. #7
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    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

  8. #8
    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

  9. #9
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    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.

  10. #10
    Join Date
    Aug 2010
    Posts
    6

    @kitman

    I couldnt get u sir

  11. #11
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •