Find the answer to your Linux question:
Results 1 to 2 of 2
Hey all and happy holidays, I am just starting to mess more with writing my own bash scripts and I have run into a situation I can not seem to ...
  1. #1
    Just Joined!
    Join Date
    Oct 2010
    Posts
    5

    Troubles with my bash script

    Hey all and happy holidays, I am just starting to mess more with writing my own bash scripts and I have run into a situation I can not seem to work around as I do not think I am going about things properly. What I want to achieve is the following:
    1. check if a file exists in a folder
    2. if it does not exist then wget the package
    3. if it does exist then wget -N to see if the version in the folder is older than the one online
    4. if it is newer then download the new version

    I know there has to be better ways of going about what I am trying to do and I am open to any suggestions and or info

    what I would also like to have it do is instead of me checking for a specific program version in the folder, have it get what version number is in the folder if its in there then check to see if there is something newer. If you need any more info or anything please let me know. Thanks a ton

    *I had to put hxxp since I cant post links yet

    Code:
    #!/bin/bash
    #
    # Script to check for newer version of files that I will keep on hand for the Fed and Build installs Only 
    #
    # Variables
    USERNAME=vdubhack
    FOLDER=/home/$USERNAME/other/programs/
    #
    if [ ! -f "$FOLDER/cudatoolkit_3.2.16_linux_64_fedora13.run" ]; then
                cd $FOLDER
                wget hxxp://developer.download.nvidia.com/compute/cuda/3_2_prod/toolkit/cudatoolkit_3.2.16_linux_64_fedora13.run
                echo "Cudatoolkit did not exsist downloading"
        elif [ == -f "$FOLDER/cudatoolkit_3.2.16_linux_64_fedora13.run" ]; then
                 wget -N hxxp://developer.download.nvidia.com/compute/cuda/3_2_prod/toolkit/cudatoolkit_3.2.16_linux_64_fedora13.run
                 echo "there was something newer only"
    
        else
                  echo "nothing to do file was there and nothing newer online."
    
    fi

  2. #2
    Just Joined!
    Join Date
    Jun 2010
    Posts
    6

    Check the wget man pages

    I think you can just use some combination of no clobber and newer (-rN maybe?) and turn this into a one-liner.

    Sorry don't have a Linux shell to test with, but maybe just:

    Code:
    $ wget -Nr hxxp://developer.download.nvidia.com/compute/cuda/3_2_prod/toolkit/cudatoolkit_3.2.16_linux_64_fedora13.run
    In the future, if you find your script doing this:

    Code:
    if [ case ]; then
      code1
    elif [ ! case ]; then
      code2
    else
      # noop
    fi
    Then it should be:
    Code:
    if [ case ]; then
      code1
    else
      code2
    fi

Posting Permissions

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