#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    35
    Rep Power
    5

    SCP error: No such file or directory


    Hi,


    I am trying to do scp using the following script:
    Code:
    #!/usr/local/bin/bash
    
    BUILDDATE=20120220
    
    for line in `cat arch_host_plat_src_dest`
    do
            src=`echo $line | cut -d: -f4`
            dest=`echo $line | cut -d: -f5`
    
    	echo scp -p /builds/${BUILDDATE}/Integration/$src  root@10.216.123.456:/builds/gc/$dest
            scp -p /builds/${BUILDDATE}/Integration/$src  root@10.216.123.456:/builds/gc/$dest
    done
    I have a config file. The content of the file is given below:
    Code:
    -sh-2.05b$ cat arch_host_plat_src_dest
    HP-UX-B.11.23-pa-risc-32:EBHP1100:HPUX-HPPA:hpux-hppa/{data.cab,agent.xml}:hp/hpux/parisc
    Output
    scp -p /builds/20120220/Integration/hpux-hppa/{data.cab,agent.xml} esm2@10.216.123.456:/builds/gc/hp/hpux/parisc
    /builds/20120220/Integration/hpux-hppa/{data.cab,agent.xml}: No such file or directory


    However, the given files very much exist in the mentioned source location. Also, if the run the same command on the command line, it works without any issue.

    -sh-2.05b$ scp -p /builds/20120220/Integration/hpux-hppa/{data.cab,agent.xml} esm2@10.216.123.456:/builds/gc/hp/hpux/parisc
    data.cab 100% 51MB 5.2MB/s 00:09
    agent.xml 100% 242 305.7KB/s 00:00


    I think, this portion in the config file must be the problem area: {data.cab,agent.xml}

    I tried escaping, quoting in different ways that i could think of but couldn't get it working

    Any help?


    Thanks,
    Gaurav
    Last edited by Technext; February 23rd, 2012 at 01:30 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,467
    Rep Power
    1751
    First off, thanks for making me go search down the string expansion facility bash gives with the {} characters - I was not aware of them.
    I'd concur with you about the escaping, from the error message the shell has not processed the line as you'd expect or want. One obvious and silly question, is the shell you are running at the command line the same as the one being used by the script? Not just bash, but the same bash binary.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    35
    Rep Power
    5
    Originally Posted by SimonJM
    First off, thanks for making me go search down the string expansion facility bash gives with the {} characters - I was not aware of them.
    I'd concur with you about the escaping, from the error message the shell has not processed the line as you'd expect or want. One obvious and silly question, is the shell you are running at the command line the same as the one being used by the script? Not just bash, but the same bash binary.
    Thanks for your reply Simon! Yes, the binaries were different but even when i tried referring to the same binary, i still got the same result.

    I've just come to know from one of my friend that it's happening because the variable (src) is just reading the string from the config file. It's not expanding the content present within curly braces. He told me to convert the string into a bash var. I'm yet to try it out.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,467
    Rep Power
    1751
    Hell - misse3d (ignored/over-looked) the reading it from a file aspect. Yes, that'd be it. There are various ways to get the shell to see the {}s in the context you need, which one you choose will be a matter of style and/or preference.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    35
    Rep Power
    5
    Originally Posted by SimonJM
    Hell - misse3d (ignored/over-looked) the reading it from a file aspect. Yes, that'd be it. There are various ways to get the shell to see the {}s in the context you need, which one you choose will be a matter of style and/or preference.
    It worked after i appended 'sh -c' to the scp command

    sh -c "scp -p /builds/${BUILDDATE}/Integration/$src root@10.216.123.456:/builds/gc/$dest"


    Thanks for your time!


    Regards,
    Gaurav

IMN logo majestic logo threadwatch logo seochat tools logo