1752661 Members
5948 Online
108788 Solutions
New Discussion юеВ

Re: Shell Scripts

 
SOLVED
Go to solution
Grayh
Trusted Contributor

Shell Scripts

Gurus,

I was thinking to learn Shell Scripting now.

I have found this wonderful document in the forum:-

http://forums12.itrc.hp.com/service/forums/questionanswer.do?admit=109447627+1223574328053+28353475&threadId=178514

How to run a shell script...
Is it like ftp these scripts to the server and do
#sh <scriptname>.sh

or copy and paste the content to the root prompt...

I have done some C programming in school.. but i'm not sure if that would make my job easire..

And If I want to run some simple scripts at the root prompt.. how can I do that..

Thank you
19 REPLIES 19
Adam W.
Valued Contributor
Solution

Re: Shell Scripts

you can run them as sh .sh, or you can make them executable so that you only have to use .sh

The one thing I ALWAYS forget is the "shabang" at the beginning on the shell script, the #!/usr/bin/sh or whatever. Do you have a particular goal in mind for your scripts or just trying to learn?
There are two types of people in the world, Marines and those who wish they were.
Grayh
Trusted Contributor

Re: Shell Scripts

First I need to learn and them Implement..

Initially I want to start of with simple scripts like... to create a VG00 or VG01 ... instead of typing the commands everytime... I want to keep a script handy so that whenever needed I will do #sh <scriptname>.sh and the VG is created.

I dont know what else could be an example...

So was just trying to learn... may be in my next project I will have to use...
James R. Ferguson
Acclaimed Contributor

Re: Shell Scripts

Hi:

> I was thinking to learn Shell Scripting now...

Very good. *EVERY* good Unix administrator should be able to do basic shell programming at a minimum.

> I have done some C programming in school.. but i'm not sure if that would make my job easire..

Maybe yes; maybe no. Do *NOT* be tempted to extrapolate this into choosing the C-shell! You need to use and learn the POSIX shell --- '/usr/bin/sh' or '/sbin/sh' in our world.

> And If I want to run some simple scripts at the root prompt.. how can I do that..

NO, NO, NO! Work in your own non-root account and learn the pitfalls there, unless, of course, you have good Ignite backups and can afford to rebuild your server after you remove things!

You might start by reading:

http://docs.hp.com/en/B2355-90046/index.html

http://www.shelldorado.com/

Regards!

...JRF...
Mel Burslan
Honored Contributor

Re: Shell Scripts

In very simple layman's terms:

(root) # vi /home/user1/myscript

...
write your script here and save & exit
...

(root) # chmod o+rwx /home/user1/myscript

(root) # /home/user1/myscript

this should be all

________________________________
UNIX because I majored in cryptology...
OldSchool
Honored Contributor

Re: Shell Scripts

take a look at
http://www.shelldorado.com/

lots of tips / best practices / articles

while learning, i would be logged in as root, as a mistake can trash the system. much better to set up a login for a normal user and use that.....
Grayh
Trusted Contributor

Re: Shell Scripts

$ exit
/usr/bin/rsh: /home/vamsi/.logout: The operation is not allowed in a restricted
shell.
$


Dennis Handly
Acclaimed Contributor

Re: Shell Scripts

>Mel: chmod o+rwx /home/user1/myscript

Why would you want to do that (add w)?
chmod a+rx /home/user1/myscript
OldSchool
Honored Contributor

Re: Shell Scripts

"$ exit
/usr/bin/rsh: /home/vamsi/.logout: The operation is not allowed in a restricted
shell.
$"

So? Why is the account running rsh?

I assume this is the account that you set up for yourself so you could play with scripts, is it not? (as usual, no information)
Grayh
Trusted Contributor

Re: Shell Scripts

When I do the following I have an error.. what does it mean

$ exit
/usr/bin/rsh: /home/vamsi/.logout: The operation is not allowed in a restricted
shell.
$

Also what does the below mean

$ /usr/local/bin/sudo su-
sudo: /usr/local/etc/sudoers is mode 0666, should be 0440