Sponsored Content
Full Discussion: Scripting Best Practices
Top Forums UNIX for Dummies Questions & Answers Scripting Best Practices Post 65684 by indo1144 on Tuesday 8th of March 2005 04:04:10 AM
Old 03-08-2005
Power Scripting Best Practices

When I first had the need to write scripts, this was the first place I looked. Here's some of the things I always do:
  • Before writing any code, know exactly what it is you want your script to do and plan for the unexpected (error-handling, false user-input,etc).
  • Write clean code, use indents and use comments to explain parts of your code!!!
  • Scripting works better if you feel comfortable using shell-commands on the host-system.
  • Variables are your friends!
  • Use functions.
  • Open another terminal and try out parts of the code to see its output on screen (good for those extra spaces that screw up IF-statements).
  • In case of the above, sed is your friend.
  • More friends: awk, head, tail, wc, grep, ps, etc...
  • Apropos is your friend too.
  • Get comfortable using a text-editor like vi, if all else fails I recommend UltraEdit which is extremely handy.
  • Don't be affraid to ask someone else if you're stuck. You can find my share of stupid questions on this forum, but you know what? I just started out then. My position now? I write really really large scripts for my company and they have come to depend on them!
  • Word of caution: sometimes scripts really stress a server. Try to be there the first few times they run, just in case. Smilie
  • Use logging when needed. Create a log-function, so you don't need then ">" and ">>" to write to or append to a logfile. One typo can clear your logs. Using a log-function prevents this.
  • Many of my scripts send me email. To stop the confusion Smilie , I always print the name of the script in the mailmessage, you'll start to appreciate this!
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Korn Shell Best Practices

I am new to ksh scripts (still reading manuals). I need to write an application that reads a multi-line parameter file, builds sql on-the-fly, runs plsql and saves the output in a specific format for further processing. I am looking for anything on Best Practices for building such an... (1 Reply)
Discussion started by: mtravis
1 Replies

2. UNIX for Advanced & Expert Users

emergency shutdown best practices.

Has anyone implemented or have suggestions on how to shutdown many remote unix/linux servers from a single script initiated from 1 server? I need this to execute in parallel as time is not on my side. Our ups is sadly underrated and will die in approximately 15 minutes. (There is not... (10 Replies)
Discussion started by: jsw371
10 Replies

3. Shell Programming and Scripting

shell scripting best practices - trap command

I know there is a command called trap which can be used to capture the signals from a shell script and redirect the control to a required function (such as a cleanup). My question is - Those of you who have written lot of shell scripts - do you always write a set of trap commands to capture... (4 Replies)
Discussion started by: sagar_evc
4 Replies

4. UNIX for Dummies Questions & Answers

Best practices for Source control

Hi all, i am trying to incorporate source control management in my project. We have about 50 - 60 shell scripts on 3 different machines dev, stag and production, but there is no source control. All the files have to be located at specific locations on each machine for it to work I want to... (4 Replies)
Discussion started by: chvs2000
4 Replies

5. Shell Programming and Scripting

Global Script Best Practices

Hey there. I am a relative rookie when it comes to Linux/Unix Administration and have been learning to adapt my meager coding skill to working with shell scripts in the 'nix realms. I have done some exhausting searches for and found plenty of information on making scripts globally available but... (2 Replies)
Discussion started by: Tenuous
2 Replies

6. Solaris

Best practices

Dear all, Kinda lame question but i'd like to hear your experiences and advice. Question in short ----------------- What permission should a mount point "ideally" have - i think it's root. Ex:- /usr/app/ i'd set the app to be owned by root and within /usr/app i would create another... (1 Reply)
Discussion started by: ossupport55
1 Replies

7. Linux

Virtualization best practices

Hello admins and gurus I have a controversial topic: now we are investing in a new Linux OS that will hold our Sybase database. The server will virtualized on a VMware server hosted on SAN storage. Now the question is, when we install the database engine is it better - in terms of performance -... (1 Reply)
Discussion started by: abohmeed
1 Replies
All times are GMT -4. The time now is 02:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy