Sponsored Content
Top Forums Shell Programming and Scripting How to pre-check scrutinize all my shell scripts? Post 302983582 by bakunin on Thursday 13th of October 2016 11:08:36 AM
Old 10-13-2016
Quote:
Originally Posted by mohtashims
So, all of you are asking me to write a separate script to report the failing commands.

Which means i will have to look for all command in 1000+ lines of unix shell script to figure out all the commands i use in there like:
No, but you might think a bit and find a more "computerised" way of achieving this goal. You can, for instance, write a small parser, which filters out all the shell keywords and other language constructs so that only commands are being left over, which you can then feed into a while-loop for instance to process as described below.

You can probably (but with less runtime-security) forego the parser and reduce it to a matter of sequential greps to arrive at the same list. Note, though, that this will be a more error-prone (altough more easily to achieve) alternative, because parsing adds context to the processed code which filtering doesn't (to add some theoretical background: the difference between Chomsky-Type 3 and Chomsky-Type 2 grammatics coming in here).


Quote:
Originally Posted by mohtashims
However, i wanted to know if it is somehow possible that my scripts are automatically check for all commands without executing the script & without me having to provide all commands in the check.
What exactly do you mean by "automatically"? If i remember correctly (Don Cragun may help out here) /usr/bin/dowhateverineed was not part of the POSIX standard last time i checked, so: no, you won't get that automatically. You will have to do work to achieve results like the rest of us.

Quote:
Originally Posted by mohtashims
So, if any new script is introduced i should be able to validate all the command in that script without executing the script & without manually traversing line by line looking for unique commands in the scripts.
Here is an idea: implement, what i proposed before, put that into a script, pass to this script the name of a another script you want to check, let the script go over the process of extracting commands and then, for every command found, execute a test if this command exists at the target system. This takes already care of the "command not found"-problem.

Here is another idea, which might sound a bit outlandish: STICK TO THE POSIX STANDARD! There are a lot of POSIX-certified platforms and even non-certified platforms will for most parts adhere to the standard. So, if you use only what is in this standard you will at most times be on the safe side even without complicated tests. If you want to use every obscure platform-specific speciality you are doomed to ultimately fail anyway, having tests or not. So, how about changing your working habits instead of wanting to change the world?

Frankly, i work in environments where i have to deal with up to a dozen different platforms (different OSes, different versions, etc.) and my scripts usually work even in these environments without problems (that is: problems coming from this diversity - my scripts are not flawless at all, but i don't have your problems). And 1000 lines of shell code is a typical size of one of my scripts, of which i have (and use) many dozens. My pity for you to have to manage 1000 lines of code is somewhat limited.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

2. UNIX for Dummies Questions & Answers

How to check the unix scripts currently running

I have a Unix box abcd, where I have script1, script2 and script3 running. I have to write a 4th script script4 which would check my box(abcd) and kill all running scripts. How can I do that? (3 Replies)
Discussion started by: Sibasish
3 Replies

3. Shell Programming and Scripting

my scripts does not check if directory exists

Hello: Can someone please help me figure out what is wrong here, my script does not move on to the "else" part even though there is no .ssh directory on my remote server: $more putkey.sh #!/bin/ksh for server in `cat list` do if ; then cat $HOME/.ssh/id_rsa.pub |ssh $server ' cat >>... (4 Replies)
Discussion started by: Sara-sh
4 Replies

4. Shell Programming and Scripting

Check if script run by a user directly or via other scripts

Hi, i have a script 'a.sh' that should be called only by certain scripts like b.sh, c.sh Inside a.sh, how can i determine 1) if this script was run directly from command prompt (or scheduler) 2) if called via other scripts? Is there an easy way to get parent process name (not just pid),... (2 Replies)
Discussion started by: ysrinu
2 Replies

5. Shell Programming and Scripting

1 script or multiple scripts?? - check files, run jobs

Question for anyone that might be able to help: My objective is to eheck if a file (a source file) exists in a directory. If it does then, I'd like to call an application (Informatica ETL file...not necessary to know) to run a program which extracts data and loads it into multiple targets. ... (6 Replies)
Discussion started by: jnanasakti
6 Replies

6. Linux

Call scripts in Rpm's: %pre %post sectino

Hi, In the rpm SPEC file there is %pre section for preinstall scripts. We can write any think in the "sh" format here. I want to call a script here. How can i do this? Thanks (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies

7. Shell Programming and Scripting

check exit status of bg scripts

HI All, I am running one shell script, in that script i am calling 4 scripts in the background. abc.ksh & efg.ksh & xky.ksh & mno.ksh & please let me know, how could i find the success and failure of each script. i Cannot use $?, because i want to run all the scripts in parellel. ... (2 Replies)
Discussion started by: javeed7
2 Replies

8. Shell Programming and Scripting

Check existence of a number of files and call other scripts

Hi, I am new to unix scripting and am jus getting to learn about it.. I need to know on how to check for the existence of a number of files in a path..i.e the files are ftp'ed from several other servers, should check if all the files have arrived, if not wait till they arrive..can i use a flag... (5 Replies)
Discussion started by: yohasini
5 Replies

9. Shell Programming and Scripting

Can somebody help me check over my shell scripts??

I been having a lot of trouble trying to start up a 3rd party application in Solaris 7 but it seams that its missing entry's when trying to run the files so maybe the start shells scripts have errors and maybe thatr is what is causing the issues I have added two links to the shells can anyone check... (5 Replies)
Discussion started by: Wpgn
5 Replies

10. UNIX for Beginners Questions & Answers

How to check sub scripts execution?

I have a shell script which is used to get the input and have another shell script (a sub script) at the end of this shell script which is used to upload the inputs in the Oracle database. I can check the execution status of the parent script using sh -x script.sh. but this command doesn't show the... (1 Reply)
Discussion started by: srilaxman
1 Replies
All times are GMT -4. The time now is 01:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy