1833535 Members
2946 Online
110061 Solutions
New Discussion

Scripting

 
Paul Thomson_2
Super Advisor

Scripting

I am just starting on the long scripting journey, but am having trouble coming up with ideas to write scripts about. Can anyone suggest scenarios where a script may be useful to resolve ?? Please don't provide me with any as I really need to learn. I won't hold back on the points either.
Thanks
Argh ye land lovers !
15 REPLIES 15
Michael Tully
Honored Contributor

Re: Scripting

Hi Paul,

In the below posting there was some ideas and scripts actually attached. You could without cheating use the ideas and write you own, without looking at the attachments....

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x026250011d20d6118ff40090279cd0f9,00.html

The ideas are just about endless.
-Michael
Anyone for a Mutiny ?
Patrick Wallek
Honored Contributor

Re: Scripting

OK Paul. Here's one I've been considering working on.

Say you've got a test box that has HP-UX 11.0 on one disk and HP-UX 11i on another.

What I want is a script that will reset my primary boot disk for whichever version of HP-UX I want so that I don't have to interrupt the boot process if I want to reboot into the other version.

I realize that this will differ based on the hardware paths for the disks on different machines, but those could be set as command line options or variables within the script.

What do you think?
Paul Thomson_2
Super Advisor

Re: Scripting

Will have a go, may take some time though
Argh ye land lovers !
Michael Tully
Honored Contributor

Re: Scripting

Geez Patrick,

You couldn't give Paul something easier for a
beginner?

How about writing a simple menu based program
for operators that they could actually do
certain functions, like kill print jobs, users
query directories for downloads, check whether
databases are up.

-Michael
Anyone for a Mutiny ?
Patrick Wallek
Honored Contributor

Re: Scripting

Hey, he asked for ideas Michael. That really is something I've been thinking about doing. I really don't think it should be that difficult. I've had the framework of the thing in my mind for a while. I just haven't gotten around to getting it typed in yet.

Paul Thomson_2
Super Advisor

Re: Scripting

Michael

Have been dabling with basic menus and stuff, I have attached an example, suppose I just want to walk before I can crawl.
Argh ye land lovers !
Michael Tully
Honored Contributor

Re: Scripting

Hi Paul,

That's not a bad attempt at all. Certainly the
framework is there. I have two further suggestions for you which I don't believe were in the link I gave you before.

Write a script that monitors essential processes that are supposed to be running on your system.
e.g. inetd, vhand, statdaemon, lpsched, others
that you may need for your applications. You
could start this script once out of inittab
and have it wake every x minutes to run again.

The second one is more for security, where you
could monitor certain files for changes, set a
baseline, tell you what the changes are and
e-mail you the differences. These files could
include, passwd, group, inetd, services,
resolv.conf, sudoers (if used).

HTH
-Michael
Anyone for a Mutiny ?
Paul Thomson_2
Super Advisor

Re: Scripting

Michael

Thanks for advice, will get cracking. One of the problems I have is that I do not really get a chance to do scripting as it is done by others. And thing such as inetd etc have already been done. Will plug on though and see where this get me.
Thanks
Paul
Argh ye land lovers !
steven Burgess_2
Honored Contributor

Re: Scripting

Paul

What about scripts that would aid investigation with regard to application support?

You could look at some of the investigations performed by the helpdesk and simplify these
with the use of a script, looking in log files, C-ISAM files for entries errors etc
take your time and think things through
Steve Steel
Honored Contributor

Re: Scripting

Hi


Great Examples

http://www.introcomp.co.uk/examples/index.html


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
H.Merijn Brand (procura
Honored Contributor

Re: Scripting

Not that I want to take away the joy of writing a scripted menu system, but attached is a perl/Tk script I wrote as a training for myself to mimic the behaviour of the same written in C.

If you've got all the required modules installed, cp the three files to /tmp and

/tmp # xamen -m.

Since the quest was for scripting, I guess you're not interested in the C program :)
Enjoy, Have FUN! H.Merijn
George_Dodds
Honored Contributor

Re: Scripting

Hi Paul.

If you want something to get your teeth in why not take a look at cfg2html.

http://members.tripod.com/rose_swe/cfg/cfg.html

You could see if you could do something similar without taking a look at the script.

You could also write a script for a basic system monitoring that would mail the sys admin, say for example when filesystems fill up or if the cpu is at 100%, etc.

Have fun

George

A. Clay Stephenson
Acclaimed Contributor

Re: Scripting

Hi Paul:

Here is a useful idea and it will also teach you a valuable concept:

Given a list of Process ID's (pids) supplied on the command line, your script should kill each one BUT using this method:
Send kill -15, -1, -2, -3, and kill -11 in that order and testing via kill -0 pid with a brief sleep to see if the kill succeeded.

The idea is that you would send -kill -15, sleep a bit, and test to see if the process still exists before trying kill -1. If and only if a -k is supplied to your script would you finally send a kill -9.

Your script should use getopts to process the command line. You should study why kill -9 is a very bad idea though it is taught as a routine practice in many Kindergarten Admin classes. You should man getopts and kill for details. You will actually find that this will become a very valuable addition to your sysadmin toolbox.

Food for thought, Clay



If it ain't broke, I can fix that.
harry d brown jr
Honored Contributor

Re: Scripting

Paul,

The best way to learn is to see how other people tackled issues. Having access to sample scripts is the most helpful thing a sysadmin could have. You should also contemplate learning perl, along with the standard sh and ksh scripts.

live free or die
harry
Live Free or Die
Darrell Allen
Honored Contributor

Re: Scripting

Hi Paul,

How about a script to schedule a make_tape_recovery backup with the "at" command?

-validate "at" arguments passed to the script
-accept and validate "tape drive to use" argument
-verify a tape is in the drive - if not, tell the user and ask if he wants to continue
-verify args are entered and provide a "usage" message if not
-add to a log file a message that this script ran, by whom, when, and when the make_tape_recovery is scheduled for

I use a script like this now as well as a few others to "schedule" things I do infrequently and don't want to have to remember the syntax.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)