LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-31-2009, 04:08 PM   #1
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Rep: Reputation: 0
Unix Script Help Need


Hello,
Can anybody help me with a unix script project that I have no clue on starting it, and also I 'm not that much familiar with unix scripting. Don't get me wrong have little bit experience with Linux, but when comes to script I'm just a beginner. If any someone can assist me with project that would be great. At the bottom is the description of the project:

PROJECT 3

Create your own shell that will allow you to change file status and copy from one directory to another.


If someone can help with this project.

Thanks
Deven
 
Old 10-31-2009, 04:13 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 11,853

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Welcome to LinuxQuestions

Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.
 
Old 10-31-2009, 04:16 PM   #3
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
What did you learn in Project 1 and 2 ?

Can you apply that to Project 3 ?

Obviously your prof must have explained how to do what you need to do.
Where are you stuck?

Last edited by dxqcanada; 10-31-2009 at 04:18 PM.
 
Old 10-31-2009, 04:22 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Creating a shell isn't the same as creating a script, unless you mean to create a script that emulates a shell.
Kevin Barry
 
Old 10-31-2009, 05:43 PM   #5
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
I asked the professor to provided any example that help with doing this project, this what he provided:

Dear Deven:

The menu structure I mentioned can be created with the following template:

echo "Please choose a folder or file. If you choose a folder you will move into that folder. Enter nothing to exit."

read choice

if [ "$choice" != "" ]; then

if [ -f $choice ]; then

echo "$choice options:"
echo "Type hide to hide file."
echo "Type copypro to copy protect."
echo "Type read to set ready only."
echo "Type copy to copy a file from one directory to another."
echo "Type exit to choose a different file."
read op

case "$op" in

hide)
# code for hide
copy)
# code for copy
copypro)
# code for copypro
read)
# code for read
exit)
# code for exit
*)
# code for error
esac
else
cd $choice
fi

fi




So if this what's looking for, then I do have the little bit idea. The only part I really stuck is creating a your shell. So, if someone can provided me the material, or guide me on getting the first part clear. Then I can work the project.

Sincerely,
Deven

PS Moderator, I'm sorry about the rule, which I didn't follow. My mistake, and I'll make sure next time.
 
Old 11-01-2009, 08:51 AM   #6
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
As ta0kira stated ... are you sure your Prof asked to
Quote:
Originally Posted by deven1174 View Post
Create your own shell ...
or did they ask you to:
"Create your own shell script ..."

These are two very different things.
 
Old 11-01-2009, 11:48 AM   #7
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
It seems clear from the professors reply:
  1. You are creating a shell script
  2. The script is menu driven
  3. You have covered (or should have) case statements
  4. You have covered reading input and checking the responses

Your professor has also provided the starting point for your homework:
Code:
echo "Please choose a folder or file. If you choose a folder you will move into that folder. Enter nothing to exit."

read choice

if [ "$choice" != "" ]; then

   if [ -f $choice ]; then

      echo "$choice options:"
      echo "Type hide to hide file."
      echo "Type copypro to copy protect."
      echo "Type read to set ready only."
      echo "Type copy to copy a file from one directory to another."
      echo "Type exit to choose a different file."
      read op

      case "$op" in

         hide)
            # code for hide
         copy)
            # code for copy
         copypro)
            # code for copypro
         read)
            # code for read
         exit)
            # code for exit
         *)
            # code for error
      esac
   else
     cd $choice
   fi
fi
Meaning all you need to do is create the code for each option (hide, copy, copypro etc)

Where are you having difficulties?
 
Old 11-01-2009, 11:56 AM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
What does "copypro" mean?
Kevin Barry
 
Old 11-01-2009, 12:17 PM   #9
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
As in the professor's instructions copypro (copy protection)

All of the options seem to be permission related, therefore alot of this will probably fall down to using chmod. But there may well be some PAM in use, not being on the course I couldn't say for sure
 
Old 11-01-2009, 12:31 PM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,533
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
The prof's code:
  • fails if $choice contains embedded whitespace.
  • does not follow good practice by using [ ] rather than [[ ]] and by using " when ' will do.
  • has a typo of "ready" for "read".
  • is ineffective and lacks error code when the user chooses a "folder" (we have folders on Linux?).

@deven1174: I dare you tell the prof all those things!
 
Old 11-02-2009, 07:44 AM   #11
deven1174
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Here's is professor comment:

Yes, file status means permissions enable/disable. I am assuming that you have to provide for all the options you have on lab2. The template I gave you goes beyond that.

Lab2 solution:

#!/bin/ksh

cd North
find ./ -type f -exec chmod 555 {} \;
cd

# in order for a file to be read only and not be useless, it must be executable. Doing chmod 444 as you did is no good.

cd East
find ./ -type f -exec chmod 333 {} \;
cd

cd West
find ./ -type f -exec chmod 333 {} \;
cd

# In order to be copy protected, you must disable the read permission. Doing chmod 744 as you did is no good.

cd South
for var in *; do
if [ -d "$var" ]; then
cd $var
for var in *; do
if [ -d "$var" ]; then
cd $var
for file in *; do
mv "$file" ".$file"
done
cd ..
else
mv "$var" ".$var"
fi
done
cd ..
else
mv "$var" ".$var"
fi
done

# South is more tricky. You do not want to hide the whole South structure, but just the files. So you have to use something like the code above, to find and hide only the files.


I'm kind a beginner when comes to Unix Scripting. I don't mind learning it, but with Project3 is due tomorrow. I kind running out of time. If anybody could help with this Project.

Than You for your help

Deven

Last edited by deven1174; 11-02-2009 at 07:48 AM.
 
Old 11-02-2009, 10:46 AM   #12
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You haven't actually posted code you've written yourself and tried...
Kevin Barry
 
Old 11-02-2009, 11:03 AM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
I'm kind a beginner when comes to Unix Scripting. I don't mind learning it, but with Project3 is due tomorrow. I kind running out of time. If anybody could help with this Project.
Have you told us what references you are using (I might have missed it..)

Also, what shell? Here in Linux-land, we mostly use BASH, which is derived from the Unix Bourne shell. I'm not sure what all the differences are.

As far as getting help here, the best thing at this point would be to take specific questions---show us your code (or what you have read), and tell us specifically what you don't understand.

Quote:
I don't mind learning it
It seems that it is required for your class, so I'd like to hear: "I want to learn it."
 
Old 11-02-2009, 03:30 PM   #14
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
So what you are saying (or quoting) is:

"Read only" equates to chmod 555 "$choice"
"Copy protected" equates to chmod 333 "$choice"
"Hide" equates to mv "$choice" ".$choice"
"Copy" will require asking for the new location (and testing that it is a directory)

It seems to me that you have everything, that your professor has all but spelt out the answer.
 
Old 11-02-2009, 05:14 PM   #15
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
Deven ... what we are saying here is ... you show us that you have made an effort in doing your own homework ... and then we will help by offering suggestions to specific points you are having problems with.

We will not do your assignment for you.

Show us what you have done.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with a basic UNIX script mike9287 Linux - Newbie 28 06-02-2006 02:14 AM
script under UNIX\Linux OS symbalino Programming 11 05-28-2006 07:50 AM
unix shell script cxy0481 Programming 9 11-20-2005 08:15 AM
Problem in the Unix Script triplek4ever Linux - Networking 3 10-27-2003 01:25 PM
How to schedule unix script periodically from unix os level??? gopi_20us Programming 2 03-11-2002 06:45 AM


All times are GMT -5. The time now is 09:18 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration