How to Automate SCP...

Discussion in 'Programming/Scripts' started by ramesh_rncbe, Aug 12, 2009.

  1. ramesh_rncbe

    ramesh_rncbe New Member

    I am trying to move files from local server to remote unix server...
    for that I am using SCP to achieve this....

    I have written script to achieve this but with password prompt....
    Login username on remote is tester1...
    After login i will do sudo to login as the application user...
    thru sudo command...
    Eg : Sudo /usr/local/bin/mcfs
    mcfs -> Application user....
    After doing scp..if i try ll command...
    it shows the UID as tester1... but we need it as mcfs application user.. so that developers can access the file without any problem...

    Above task is achieved by using shell script but only as tester1 not with sudo user...

    Any help would be really apprecaited...
  2. id10t

    id10t Member

    You need to scp the files as the MFC user

    scp somefile [email protected]:/path/to/copy/file/to

    You could also set it up wtih passwordless SSH keys to automate copying so you don't have to enter a pw
  3. ramesh_rncbe

    ramesh_rncbe New Member

    Thanks for your reply... please look at the script and help me on this....

    # INI_FILE is the input file that's where we have the host , Remote host and # source and destination directories mentioned.
    if [ -f ${INI_FILE} ]
    #Run the INI_FILE
    echo "Running INI FILE"
    . ${INI_FILE}
    echo "${INI_FILE}"
    echo "${HOST}"
    echo "${D_HOST}"

    echo " \n Environment file <PATH.INI> not present. Please check. \n"
    exit 1

    perm() {

    cd ${SRC_DIR}
    chmod -R 775 *


    File_Transfer() {

    cd ${SRC_DIR}
    cat /home/pvcs/Ram/ | ssh ${USER}@${D_HOST}
    # is sudo user file.. where the below mentioned command will # be executed....
    #sudo /usr/local/sbin/mcds

    # sudo /usr/sbin/sudo/mcds
    scp -p ${SRC_DIR}/*.sh ${USER1}@${D_HOST}:${DES_DIR}


    Can you help me how to add the mfc user in this scripts... i am new to scripting...
    Any help would be really helpful...

Share This Page