Find the answer to your Linux question:
Results 1 to 4 of 4
I'm new to shell scripting and have a problem with a script. The problem is with this statement: cp -rp "$DEVPATH/httpdocs/[!.]*" "$LIVEPATH/httpdocs" The console puts out cp: cannot stat `/var/www/vhosts/q2.com/httpdocs/[!.]*': ...
  1. #1
    Just Joined!
    Join Date
    Aug 2007
    Posts
    3

    cp $path/[!.]* doesn't work

    I'm new to shell scripting and have a problem with a script. The problem is with this statement:

    cp -rp "$DEVPATH/httpdocs/[!.]*" "$LIVEPATH/httpdocs"

    The console puts out

    cp: cannot stat `/var/www/vhosts/q2.com/httpdocs/[!.]*': No such file or directory

    If I manually type that line at the shell prompt it works fine.

    Code:
    #!/bin/bash
    LIVEPATH="/var/www/vhosts/qTEST.com"
    DEVPATH="/var/www/vhosts/q2.com"
    
    clear
    echo -ne "Have you updated all the database tables and set the SITE constant\nto 'live'? (yes/no) "
    read READY
    
    if [ "$READY" = "yes" ]; then
            alias cp='cp' # override cp-I alias
            rm -rf "$LIVEPATH/httpdocs.bak"
            cp -R "$LIVEPATH/httpdocs" "$LIVEPATH/httpdocs.bak"
            # [!.] excludes files starting with a ., specifically htaccess/htpasswd
            cp -rp "$DEVPATH/httpdocs/[!.]*" "$LIVEPATH/httpdocs"
            chown -R jbronec "$LIVEPATH/httpdocs"
    
            echo -e "\nThe dev files have been copied to live.\nMake sure you rebuild the homepage cache and change the SITE constant\non dev to 'dev'"
    else
            echo -e "\nYou need to update the database tables and SITE constant first."
    fi

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Hi,

    cp don't copy files with names started with a dot (hidden files).
    Try this (without double quotes):

    Code:
    cp -rp $DEVPATH/httpdocs/* $LIVEPATH/httpdocs
    instead of:

    Code:
    cp -rp "$DEVPATH/httpdocs/[!.]*" "$LIVEPATH/httpdocs"
    To copy all (hidden and regular) files you can do this:

    Code:
    cp -rp $DEVPATH/httpdocs/ $LIVEPATH/
    To copy only hidden files:

    Code:
    cp -rp $DEVPATH/httpdocs/.[a-zA-Z0-9]* $LIVEPATH/
    Regards

  3. #3
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    -a, the archive option I believe is synonymous with -rp. I use it frequently

    Err correction, it's the same as -dpR

  4. #4
    Just Joined!
    Join Date
    Aug 2007
    Posts
    3
    Actually, the quotes were the problem. I removed them and it works fine. Thanks.

Posting Permissions

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