# UNIX Script using vi - HELP!



## troy86 (May 23, 2006)

Hi Guys, i've got myself into a bit of a mess, i am supposed to be helping my friend do an assignment for his Operating Systems class at uni, it's due in a week and he need's to make a script in vi, using bourne shell, and i have no idea about how to do it !

I've been messing around trying to learn how to use vi for about 2 hoursd and im not getting anywhere.

Could someone help me with the script for this?

The program:


Execute the program, display 4 options

1. home directory, mail directory, path,
userid and the login shell

2. use ps, to print all the process' that are running, and sort them in reverse order using the COMMAND column of the output as the key

3. Print a long listing of the files in the specified directory for a specific month

4. and exit the program

Only 1 option can be selected at a time, and the menu has to display over and over again until 4.Exit, get selected.


If someone could help me with this it would be greatly appreciated

Kind Regards,

Troy


----------



## tomdkat (May 6, 2006)

Are you wanting help with using vi to write the script or are you asking US to do the homework for you? 

Peace...


----------



## linPhile (May 8, 2006)

Hi Troy,

It's relatively easy to do a prompt for options.

Try this for a start:

echo "enter some information please: "
read ANSWER
echo "you entered: "$ANSWER 

Then add some case statements to that with your four options and you should be set


----------



## linPhile (May 8, 2006)

By the way, what does all this have to do with vi?

It seems like you could use your editor of choice to write the shell script. Use notepad(but remember that the lines end differently) or vim(vi improved) or Emacs. As long as you save the file in text-only format with the proper line endings, it shouldn't matter at all. If your friend is at University, the servers he/she will be using will likely offer a ms2ux or some other type of conversion program that will modify the newline chars at the end of each line to suite the system you want to convert from-to.


----------



## Squashman (Apr 4, 2003)

Not really that hard.

all you need is a While loop, case statement that makes a few function calls and do all your execution in the functions.


----------



## troy86 (May 23, 2006)

thanks guy's, you obviously know what your talking about,

I downloaded and tried using vim on my pc, but i have basically no coding background at all, i work for a web design company at the moment, and a have done vb back in year 10 at school 

i'd love it if someone who has done a script similar could show me, it's killing me


----------



## Squashman (Apr 4, 2003)

I actually have a really good book on Bash Scripting, but you can go here to learn alot.
http://www.tldp.net/LDP/abs/html/index.html

You don't need to write the script in VI or on linux. You just need to make sure it is in the unix text file format when you run it on the linux box. Sometimes I just write stuff in Notepad and then transfer it to my machine and do the old dos2unix commmand.


----------



## lotuseclat79 (Sep 12, 2003)

Are the four options:
directory: either home or mail
path
userid
login shell

or do you mean 5 options?

Or, do you mean the first 4 are the options, and the login shell is along for the ride?

Also, how is the calendar month specified, e.g. as another option?

-- Tom


----------



## troy86 (May 23, 2006)

Execute the program, display 4 options


The program, i think need's 4 option

the first, ill call, myinfo
and should display:
home directory, mail directory, path,
userid and the login shell

the second ill call, processes, and should use ps, to print all the process' that are running, and sort them in reverse order using the COMMAND column of the output as the key

the third should Print a long listing of the files in the specified directory for a specific month

and the final option should exit the program

Only 1 option can be selected at a time, and the menu has to display over and over again until 4.Exit, get's selected.

That's my understanding of what it need's to do anyway. tis hard, i've been trying to learn vi from scratch, and i have no idea what im doing


----------



## Squashman (Apr 4, 2003)

You don't need to write the script in VI. It doesn't really matter what text editor you write it in. You just need to make sure it is in the unix file format. If you write the script in Windows and then transfer it to a Linux machine, you need to run the dos2unix command on the file.

I would bet Pico is loaded on that machine. use that. I am a hard core VI person though, so I know all the commands for the most part but Pico is probably better for most people.


----------



## lotuseclat79 (Sep 12, 2003)

Hi Troy,

The critical knowledge needed to solve this problem assumes:
1) knowledge of the Unix/Linux commands - use the man pages for the commands
2) familiarity with how to program in Bourne Shell script language - this is more important

As for vi or vim, I have attached a list of Vim commands I found lying around. You can actually use any available editor as has already been pointed out.

Suggest you Google for: "how to" & program & 'Bourne shell script"

-- Tom


----------



## troy86 (May 23, 2006)

Nope, im absolutely screwed, we have been sitting here trying to do it and we can get it to display the 4 options, and thats it.. nothing else works.

This is hopeless, and i cant find the bloody time to read a full book. i have my own UNI course to do, not to mention work.

Can anyone write the code for one or two options so we can try and copy it for the other 2? we really need someone who is proficient in VI and shell scripting with UNIX to be in the same room, and take us through the entire thing step by step.

I can't believe how bloody hard this is.

If someone can help me out with this i would be happy to design them a website for something in appreciation. at least im good at doing that!


----------



## troy86 (May 23, 2006)

ok, this is the actual assignment sheet

http://www.academic.mit.edu.au/dling/links/it225/labs/it225_Assignment_TP1Y2006a, print.pdf

I will transfer $30 AUD and Build a website for someone who can create this script before 10am January 1st

and post it here to be printed off.

I will honour my word, and be greatly appreciative.

This is officially impossible.

Troy


----------



## Squashman (Apr 4, 2003)

Why not post what you have started and we can probably help you from there. This script really isn't that difficult to do. I think you should have enough time to get it done by January 1st of next year. You should be able to get it done by next week if your friend payed any attention in class.

It is really not worth $30 of my time to write the whole script myself, but I would be more than happy to help you figure what is wrong with your existing code.


----------



## ~Candy~ (Jan 27, 2001)

His other thread says tomorrow............


----------



## Squashman (Apr 4, 2003)

There seems to be a rip in the time space continuim. Can someone get Jorde working on that.


----------



## fenderfreek (Mar 14, 2006)

Sounds like someone used CSCxxx class for naptime...


----------

