Linux scripting. Help needed.

    • Rihard4a
      Rihard4a
      Bronze
      Joined: 08.09.2010 Posts: 2,064
      Okay guys. So here is the problem of mine. I have to make 3 scripts for my coursework. So that it kinda represents Windows environment.

      Scripts #1 ( which works good, but need some fixing ) has to delete files ( not actually delete, but move the files to a directory called dustbin, which is a recycle bin without physically deleting the file. ) also this script should store files old location into a file called storage, which is located in home directory (it will be required for script #3 for restoring files).

      Script #2 is a trash script, which clears the recycle bin ( dustbin ), it's function should be like this. if you type in command prompt trash it should attempt to delete files but prompting for each files whether users wants to delete it. If command entered as trash -a then it should clear files from directory without any warnings.

      Script #3 should restore files from the dustbin if they are still there to their original location from where they were moved to dustbin by typing restore <filename>. I have provided my so far scripts. If anyone here has some knowledge in Linux scripting, please help me!


      #del script #1

      #!/bin/sh
      if [ $1 ] ; then
      echo "Do you want to delete this file?"
      echo "y/n"
      read ans
      case $ans in
      y) echo "`readlink -f $1`" >>home/storage & mv $1 /home/dustbin ;;
      n) echo "File not deleted." ;;
      *) echo "Please input answer." ;;
      esac
      else
      echo "Usage: del <filename."
      fi




      #Trash script #2

      #!/bin/sh

      dustbin="/root/home/dustbin"

      ASK=1
      if [ "$1" == "-a" ] ; then
      ASK=0
      fi

      if [ ! -d $dustbin ] ; then
      echo "dustbin does not exist or is not a folder."
      exit 1
      fi

      cd $dustbin

      for foo in * ; do
      if [ -f $foo ] ; then
      if test $ASK ; then
      rm -f $foo
      else
      echo -n 'Delete file '"$foo"' [y/n]? '
      read $response
      if [ "$response" = y ] ; then
      rm -i $foo
      fi
      fi
      else
      echo "$foo is not a file I can delete."
      fi
      done

      echo "Done cleaning dustbin."



      #restore script #3

      #!/bin/sh

      if [ "$1" == "-n" ] ; then
      cd ~/home/dustbin
      restore="$(grep "$2" "$home/storage")"
      filename="$(basename "$restore")"
      echo "Where to save?"
      read location
      location1="$(readlink -f "$location")"
      mv -i $filename "$location1"/$filename
      else
      cd ~/home
      storage=$home/storage
      restore="$(grep "$1" "$storage")"
      filename="$(basename "$restore")"
      mv -i $filename $restore
      fi
  • 7 replies
    • Rihard4a
      Rihard4a
      Bronze
      Joined: 08.09.2010 Posts: 2,064
      Another point to add. For script #1 which is delete script. If it sends a file to dustbin with the same name that already exists there, it should NOT overwrite it but store preferably with similar name.
    • TiciBoy
      TiciBoy
      Bronze
      Joined: 13.01.2010 Posts: 1,235
      Don't know how many programmers and software developers are on this forum, but I suggest you to try asking your question on Stackoverflow. They helped me with most of my problems.

      Also can't really help you personaly since I only know some c# and Java.
    • YohanN7
      YohanN7
      Silver
      Joined: 15.06.2009 Posts: 4,492
      And I suggest you do your homework yourself.

      /Johan = :f_confused:
    • Rihard4a
      Rihard4a
      Bronze
      Joined: 08.09.2010 Posts: 2,064
      Originally posted by TiciBoy
      Don't know how many programmers and software developers are on this forum, but I suggest you to try asking your question on Stackoverflow. They helped me with most of my problems.

      Also can't really help you personaly since I only know some c# and Java.
      Thanks for the tip. Gonna look through that.

      Originally posted by YohanN7
      And I suggest you do your homework yourself.

      /Johan = :f_confused:
      I do it myself. I just need some guidance because it is not fully done. Someone who has lots of experience can spot mistakes and lead me to fix them. So your post is quite pointless. And I wasted 46 seconds of my life replying you.
    • TJtheTJ
      TJtheTJ
      Bronze
      Joined: 12.10.2011 Posts: 6,471
      Don't know how many programmers and software developers are on this forum, but I suggest you to try asking your question on Stackoverflow. They helped me with most of my problems.
      +1

      Stackoverflow is the way to go if there's something you can't figure out. There's basically always someone who is able to solve your problems, so long as you can show that you have at least put some effort in trying to fix it yourself, which I'm pretty sure you have ;)

      You'll generally get a reply pretty quickly, and there are a lot of people around there who can provide you top quality answers. Helped me solve some nasty problems when I did some web development shenanigans :f_cool:
    • Rihard4a
      Rihard4a
      Bronze
      Joined: 08.09.2010 Posts: 2,064
      Well actually I am nearly done with script #2 thanks to guidance of TiciBoy. Used search engine and pretty quickly found help on my problem. Still need to #3 and improve #1. Thanks for help! But if someone still has some useful advice, feel free to post, I will appreciate it!
    • YohanN7
      YohanN7
      Silver
      Joined: 15.06.2009 Posts: 4,492
      Sorry about that. I missed you spoilers. You have actually tried, and I got the reply I deserved :) .

      /Johan = :f_confused: