Sudden Problem Started using cp: command "omitting directory"

Discussion in 'Server Operation' started by bpmee, Nov 13, 2006.

  1. bpmee

    bpmee Member

    Hi All,

    Thanks in advance to anyone that can help me with this one...:)

    Just today, I'm having problems using the cp: command:

    1. Suddenly, -i (interactive) is forced upon me, even if I didn't call for it.

    2. If I use " -f ", I get an interactive prompt.

    3. I get directory not found, or "directory omitted" for the following commands, that * worked fine * up until today:

    Code:
    find /var/www/web1*/web/bmres*/myfolder/ -maxdepth 1 -type d | awk '{print "cp -f -R /home/searchfeed.php "$1"/"}' | /bin/sh
    
    
    makes error

    Code:
    
    : No such file or directory: line 12: /bin/sh
    
    
    OR, if I call it simply from the shell, as in the following:

    Code:
    
    cp -f /home/searchfeed.php /var/www/web1*/web/site*/myfolder
    
    
    makes errors:

    Code:
    
    cp: omitting directory `/var/www/web199/web/site_source_aaaadn0/myfolder'
    
    
    for EVERY web folder and site_source folder within the web1* call!

    What's up, these commands worked fine a few days ago!

    :confused:
     
  2. falko

    falko Super Moderator Howtoforge Staff

    You are using wildcards for the target directory. Are you sure you want this?

    In which script do you get this?
     
  3. bpmee

    bpmee Member

    I get that error in the first script with I listed containing the "awk" command

    Hi Falko,

    Thanks for your reply.

    I get that error in the first script I mentioned, the one containing the "awk" command...

    I want to use wildcards because I have many folders and divided into various sections throughout each "web1*" designation....

    I'm not sure why this is suddenly happening - I had no troubles before yesterday!
     
  4. falko

    falko Super Moderator Howtoforge Staff

    Please post the contents of that script here.
     
  5. bpmee

    bpmee Member

    Here's the code bit

    Hi Falko,

    Here's the code.... note, I use various iterations of it, such as web2*, web3*, etc because of the extreme amount of folders and sites on my server...

    Code:
    find /var/www/web1*/web/site*/myfolder/ -maxdepth 1 -type d | awk '{print "cp -f -R /home/searchfeed.php "$1"/"}' | /bin/sh
    echo bm1
    
    * Note, the double wild card is on purpose....

    THANKS!:cool:
     
  6. falko

    falko Super Moderator Howtoforge Staff

    Why do you pipe the output of the command through /bin/sh? :confused:
     
  7. bpmee

    bpmee Member

    I borrowed this code piece from another script I saw

    Hi Falko,

    I found this code originally from another shell script on the web.

    I just tried running it without the | /bin/sh and the shell showed the cp command, but nothing was actually copied...

    The output was like the following:

    Code:
    cp -f /home/searchfeed.php /var/www/web35/web/site_source_aaaafa4/myfolder
    
    Despite this output the file was not copied! Note, I'm trying to overwrite an existing file with a new version - perhaps I need to provide a command to remove this old file first?

    I'm hesitant to do this only because I don't want to accidentally erase other files......:confused:
     
  8. falko

    falko Super Moderator Howtoforge Staff

    Can you post your full script here, not just an excerpt?
     
  9. bpmee

    bpmee Member

    Here's the code

    Hi Falko,

    This is the full code:

    Code:
    ##
    ##
    find /var/www/web0*/web/bmres*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo bm0
    find /var/www/web1*/web/bmres*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo bm1
    find /var/www/web2*/web/bmres*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo bm2
    find /var/www/web3*/web/bmres*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo bm3
    find /var/www/web4*/web/bmres*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo bm4
    find /var/www/web5*/web/bmres*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo bm5
    find /var/www/web6*/web/bmres*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo bm6
    find /var/www/web7*/web/bmres*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo bm7
    find /var/www/web8*/web/bmres*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo bm8
    find /var/www/web9*/web/bmres*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo bm9
    ##
    ##
    ##
    find /var/www/web0*/web/site*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo site0
    find /var/www/web1*/web/site*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo site1
    find /var/www/web2*/web/site*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo site2
    find /var/www/web3*/web/site*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo site3
    find /var/www/web4*/web/site*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo site4
    find /var/www/web5*/web/site*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo site5
    find /var/www/web6*/web/site*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo site6
    find /var/www/web7*/web/site*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo site7
    find /var/www/web8*/web/site*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo site8
    find /var/www/web9*/web/site*/ -maxdepth 1 -type d | awk '{print "cp -f /home/searchfeed.php "$1""}'
    echo site9
    ##
    ##
    
    
     
  10. falko

    falko Super Moderator Howtoforge Staff

    Please put
    Code:
    #!/bin/bash 
    PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin
    right at the beginning of the script.
     
  11. bpmee

    bpmee Member

    Thanks It Worked!

    Hi Falko,

    Thanks, that additional syntax worked!

    Can you explain what it does? It looks like it is calling commands from different /usr directories...

    PS, I really appreciate the quality of assistance on this forum so I signed up for 6 months membership!:cool:
     
  12. falko

    falko Super Moderator Howtoforge Staff

    #!/bin/bash makes that the commands in the script are executed by the /bin/bash shell (otherwise the system doesn't know what to do with the commands).
    And PATH sets the directories where the script searches for commands that don't have the full path in the script. For example, if the full path for the find tool is /usr/bin/find, and you only specify find in the script, the script doesn't find find if you don't specify /usr/bin in the PATH variable.
    If you use /usr/bin/find instead of just find in the script, then you don't need a PATH variable.
     

Share This Page