Find the answer to your Linux question:
Results 1 to 2 of 2
Greetings all, im trying to write a script to check for the presence of an "update" folder, and then if its present, take files from that "update folder" and placing ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    3

    scripting to check for update folder

    Greetings all, im trying to write a script to check for the presence of an "update" folder, and then if its present, take files from that "update folder" and placing them in their respective folders...

    Psuedo Code


    Code:
    Print Output checking for updates
        If updates folder exists in folder 1
            then 
                    Print Updates Found
                    Print Updating Current Folder
                    copy file from /folder1/updates to /folder2/current
        end if
    Code:
    #!/bin/sh
    
    echo "Checking for Updates"
    if [ -d /folder1/Updates ]
      then
         echo "Updates Found"
         echo "Updating Current Folder
         ???
    fi
    Being the noob that I am (first day writing linux), Im assuming my above code seems logical. However, where the "???" exists is what Im having trouble with.

    Any assistance would be greatly appreciated.

    Regards,
    T

  2. #2
    Just Joined! pmcoleman's Avatar
    Join Date
    Jan 2009
    Location
    Colorado Springs, CO USA
    Posts
    30
    A basic solution would look something like this:

    Code:
    #!/bin/sh
    echo "Checking for Updates"
    if [ -d /folder1/Updates ]
      then
         echo "Updates Found"
         echo "Updating Current Folder"
            cp -u /folder1/Updates/* /
      else
         echo "No Update directory found in /folder1/"
    
    fi
    exit 0
    The command cp -u would copy the files in the Update directory to the root / directory only if they are newer than a file by the same name in the destination folder.

    Alternatively, you could also instantiate a loop that would test the presence of the destination directory just as you have for the /folder/Updates directory and then add a nested
    Code:
     [ -f /<destination dir>/<filename> ]
    before then using the cp -u command.

    Also, if you are really wanting to copy the said files to the root directory, user validation would be in order to check if the user is root, or a sudo user.

    It all depends on just how much validation you need. I would consider a larger script to validate if the files are really at root.

Posting Permissions

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