Announcement

Collapse
No announcement yet.

Multiple Folders - One File (FTP Q)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple Folders - One File (FTP Q)

    I have one fill I need to push to every folder inside of this one directory (100+ folders.) Anyway to write some sort of command to make it do it automatically, instead of moving each one hand?


    Maybe a separate program?

    So basically looks like this:

    www>directory1> 100 + folders

    and I need to put this one file in everyone one of those folders.

  • #2
    This should work

    Code:
    #! /bin/sh
    # Joe was here
    # 10/25/2003
    # Script : Copy 1 file to multiple users folders
    #
    # Reset Copy Counter
    x=0
    # Prompt for Filename and Location
    echo -n "Source Filename and Location [/folder/filename.txt]: "
    # Take input make it a string
    read P
    # If no input the take default source location
    if [ "$P" = "" ]; then
    P="/folder/filename.txt"
    fi
    # Filter Filename from $P and make a new string $N
    N=`basename $P`
    # Prompt for /Users/ folder location
    echo -n "Where is your users folder [/Users/]: "
    # Take input make it a string
    read D
    # If no input the take default user location
    if [ "$D" = "" ]; then
    G="/Users/"
    D="/Users/*"
    # if input then add to input /* to the end of user location
    # adding /* makes a wildcard "any folder" in /user/ 
    else
    D=$G
    D="$D/*"
    fi
    #
    # Prompt for the destination folder 
    echo -n "Where will this file be saved [/Library/Preferences/]: "
    # Take input make it a string 
    read L
    # If no input the take default user location
    if [ "$L" = "" ]; then
    L="/Library/Preferences/"
    fi
    #
    # Create Indeterminate Loop
    for F in $D 
    do
    # Take Username from $F string 
    U=`basename $F`
    #
    # Only if Directories is present filter
    if [ -d $F ]
    then
    #
    # copy $P to $F$L if no file exists -i prompts user for over write
    # $P = Source file $F = user path 
    cp -i $P $F$L
    # File Copy Counter
    x=`expr $x + 1`
    #
    # Set Owner and Group to file
    # $U = user , staff = group , change group as needed
    chown $U:staff $F$L$N
    #
    # Set File Permissions 
    # 744 = 7 User: read-write-execute
    #     = 4 Group: read 
    #     = 4 Everyone: read
    # Read = 4 , Execute = 1 , Write = 2 ,
    # None = 0 , So Read+Execute+Write = 7 , Read = 4
    # Set Permissions to file:
    # User Read Write Execute ( rwx ) , 
    # Group Read (r) , Everyone Read (r) 
    chmod 744 $F$L$N
    #
    fi
    # 
    # End Loop
    done
    # Print Total Copied Files
    echo
    echo File copied $x times
    echo
    echo Creating Log File
    echo
    echo Writing to List.txt
    # finds all files copied in $G | filters files with $N
    # then writes file locations to List.txt
    find $G -print | grep $N > List.txt
    #
    # Copy List.txt to Desktop
    cp List.txt ~/Desktop/
    # Launches TextEdit.app and opens List.txt
    open ~/Desktop/List.txt
    echo
    echo Done
    echo Enjoy
    MCSE, MVP, CCIE
    Microsoft Beta Team

    Comment


    • #3
      I run this in a SSH client, right? like PuTTY?


      Ugh, I'm a bit confused. I'm not sure what to do.

      I have a robots.txt on my desktop and need to put it in everyone of the folders underneath /html/ (Yes, I'm aware this isn't how robots.txt is supposed to be used. Don't ask. -_-...)

      I tried running the script, but I'm quite a n00b at SSH.
      Last edited by TruthElixirX; Sun 18 Feb '07, 12:01pm.

      Comment


      • #4
        Yes, SSH-2, eg: putty
        MCSE, MVP, CCIE
        Microsoft Beta Team

        Comment


        • #5
          Lame solution alert: use a mod_rewrite directive to simulate there being a robots.txt file anywhere, and instead point it to a single robots.txt file.
          --filburt1, vBulletin.org/vBulletinTemplates.com moderator
          Web Design Forums.net: vB Board of the Month
          vBulletin Mail System (vBMS): webmail for your forum users

          Comment

          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
          Working...
          X