Find the answer to your Linux question:
Results 1 to 3 of 3
i'm trying to check if both files exist and if they do i will run a code block to be developed later; otherwise skip. The files im checking need a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2010
    Posts
    14

    errors when trying to run file checks (bash)


    i'm trying to check if both files exist and if they do i will run a code block to be developed later; otherwise skip. The files im checking need a date variable and a wildcard. i peiced together some code from forums but recieved many erros shown below


    Code:
    backup:/home/myuser . /dir1/dir2/myuser_test.sh
    ' is not a typo you can run the following command to lookup the package that contains the binary:
        command-not-found
    : command not found
    ' is not a typo you can run the following command to lookup the package that contains the binary:
        command-not-found
    : command not found
    ' is not a typo you can run the following command to lookup the package that contains the binary:
        command-not-found
    : command not found
    ' is not a typo you can run the following command to lookup the package that contains the binary:
        command-not-found
    : command not found
    ' is not a typo you can run the following command to lookup the package that contains the binary:
        command-not-found
    : command not found
    will execute
    ' is not a typo you can run the following command to lookup the package that contains the binary:
        command-not-found
    : command not found
    
    backup:/home/myuser # cat /dir1/dir2/myuser_test.sh
    
    #!/bin/bash
    
    DATE=`date +%Y%m%d`
    
    #DATE=`date --date="yesterday" +%Y%m%d`
    
    #echo $DATE
    
    if [ ! -f /backup/$DATE*file.zip -o ! -f /backup/$DATE*dirs.zip ]; then
    
      echo "will execute"
    
    else
    
      echo "Did not find /backup/$DATE*file.zip /backup/$DATE*dirs.zip.  Skipping."
    
    fi

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    I'm not sure where that error message is coming from, but it looks like you are sourcing the script, versus running it. Does running it cause the same error? e.g.:

    Code:
    chmod +x /dir1/dir2/myuser_test.sh
    cd /dir1/dir2
    ./myuser_test.sh
    Maybe your wildcards are doing something unexpected when you are sourcing it...

  3. #3
    Just Joined!
    Join Date
    Dec 2006
    Posts
    3
    Hi

    I faced many times quite similar problem of gettings errors quite different.
    I am not sure if you have the same issue but worth giving it a try if not already done.

    Since you say that you have took some code from forum, i suspect that there could be some invisible special char in the script.

    try giving a dummy echo "check" after #!/bin/bash and run the script to see if you could see the echoed stgring. If not, then try running dos2unix on the script and execute it again.

    Hope it helps. Good luck

    Collins

Posting Permissions

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