1. #1
    Deleted

    help with linux restore script

    ok what i need to do is

    restore <filename> - This script should move the file called <filename> back to its original directory without requiring any further user input.
    If a file of that name already exists at the restore location, the script prompts the user to select an appropriate alternative action.

    heres what i have so far

    Code:
    #!/bin/sh
    if [ "$1" == "-n" ]
    then
      cd /root/michael/trash
      restore`grep "$2" /root/michael/store`
      filename=`basename "$restore"`
      echo "Where would you like to save the file?"
      read location
      location1=`readlink -f "$location"`
      mv -i $filename "location1"/filename
    else
      cd /root/michael/trash
      restore=`grep "$2" /root/michael/store`
      filename=`basename "$restore"`
      mv -i $filename "location1" $location
    fi
    so when i do restorn -n it ask me where i want to restore the file to, which works fine

    and if i do restore without -n it should restore the file to the original place but when i do for example
    restore test1.txt i get the error
    Code:
    mv: missing destination file operand after `'
    any idea what i need to fix it

  2. #2
    I am Murloc! Cyanotical's Avatar
    10+ Year Old Account
    Join Date
    Feb 2011
    Location
    Colorado
    Posts
    5,553
    the problem is in this line:

    mv -i $filename "location1" $location

    it might be that it's trying to read location1 from your input which should only come up under condition -n

    i think you need to redefine location1 under the else conditions

    Synthaxx would be better at this than me

  3. #3
    The problem is that your variables are not being created.

    Also why are you writing this in SH when you can write it in BASH or K-Shell with a lot easier attributes and variables.

    Also I'm not the best at SH but in BASH you don't need a ` in before GREP.

    I think what your trying to do is this (in psudeo)

    If 1 is entered, then save a file in a location that you specify, else restore / go to another location.

    Where I have a problem with your code is :
    echo "Where would you like to save the file?"
    read location
    If your variable is not defined how is it going to read the location. The only place your define a location is cd /root/michael/trash which is not entered correctly. It should be this (again in BASH): alias proj="cd /home/tree/projects/java"

    To a script that is considered definable and can be used in a "location" variable.

  4. #4
    Deleted
    Quote Originally Posted by Moonsorow View Post
    The problem is that your variables are not being created.

    Also why are you writing this in SH when you can write it in BASH or K-Shell with a lot easier attributes and variables.

    Also I'm not the best at SH but in BASH you don't need a ` in before GREP.

    I think what your trying to do is this (in psudeo)

    If 1 is entered, then save a file in a location that you specify, else restore / go to another location.

    Where I have a problem with your code is :


    If your variable is not defined how is it going to read the location. The only place your define a location is cd /root/michael/trash which is not entered correctly. It should be this (again in BASH): alias proj="cd /home/tree/projects/java"

    To a script that is considered definable and can be used in a "location" variable.
    im only started learning how to script, and your post kinda confuses me,

    how would i fix it using SH?

  5. #5
    Deleted
    sadly i tried what you suggested even put a / in with $filename/"location1" to $location, or from $filename to "location1"/$location. but still came back with an mv error

Posting Permissions

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