Sponsored Content
Top Forums Shell Programming and Scripting .sh file syntax checking script Post 302154423 by fabulous2 on Sunday 30th of December 2007 05:50:47 AM
Old 12-30-2007
Quote:
ok, don't think I'm beating up on you here, I am not. I'm only try to pass on what experience has taught me, and wouldn't bother if I though I was wasting my time, and certainly wouldn't do it just to be confrontational.
No worries: I have never felt that you are beating me up on anything. I solicited feedback, and you generously shared your knowledge with me. I appreciate that. My delay in responding is merely because I have been so busy for so long.

Speaking of overwork, I have no more time to invest in this shell script, but I have these final points to make:


1) I now think that aliases for this script (e.g. an alias for find) are no problem at all. Reason: aliases defined on the shell before executing this script are not inherited by the script when the user runs it (at least on cygwin and linux--is this true of all unixes?). Execute
Code:
alias find
alias find="lfsdllgfsdfnsdfjskjs"
alias find

on the command line; the first line should have the output
Code:
bash: alias: find: not found

while the third should have output
Code:
alias find='lfsdllgfsdfnsdfjskjs'

Then put this as the contents of the file t.sh:
Code:
#!/bin/sh
alias find

and on the command line execute
Code:
sh t.sh

I get as its output
Code:
bash: alias: find: not found

which proves that shell script files do not inherit aliases from their parent shell, at least on my systems.

Since my cs.sh file does not use any internal aliases, either explicitly or implicitly (e.g. by sourcing .bashrc or something), it should be immune from aliases.

If it was vulnerable to aliases, then the way that I would temporarily suppress them is by encasing all commands inside single quotes (e.g. 'find'), an idea that I got from
Alias (Unix shell - Wikipedia, the free encyclopedia)


2) I have been struggling for a while now to understand why you think that hardcoding full command paths inside a script--which will require a decent percentage of users to have to open the shell file and understand it and then modify it--is easier than having the user modify their path if there are issues with, say, the find command.

I stand by my approach, particularly for who my target is with this shell script (primarily script developers, not the general user).

But I now think that I can see maybe where you are coming from: are you a sys admin at a large company? Or at least a sys admin on a machine with many different user accounts but whose system level configuration (e.g. where the commands are installed) you control? Or maybe you simply always use the same unix variant so that you reliably know what paths to use. In this case, if you are responsible for writing a shell script that has to work for all your different users, then I can see why you use hard coded paths.


3) Security:
Quote:
And that is not the fully story. Don't forget security and abuse. By giving the full path you make sure you know what you are running for that reason alone your script would fail a code review in many companies.
That sounds crazy! I use relative paths, for example, in all kinds of programming applications and they are utterly invaluable (e.g. in having a configuration that always works regardless of where the user installs my package). I cannot imagine that too many companies have a policy that anything other than full paths is a security hazard.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script syntax checking

Is it possible to check the script syntax with some sort of command...? Without running the script . I'm using Sun Solaris (3 Replies)
Discussion started by: bjornrud
3 Replies

2. Shell Programming and Scripting

Simple file checking script

Hi, I have a really, what I hope is, simple question. I'm looking for a simple way to see whether a file exists or not and then perform an action based on whether it exists or not. An example of what I tried is as follows: if then { echo "File mysql exists" ... (1 Reply)
Discussion started by: _Spare_Ribs_
1 Replies

3. Shell Programming and Scripting

Script for checking and reporting file sizes in a directory.

Hi, Need help for a Script for checking and reporting database file sizes in a directory. Request you to please give your valuable inputs. Thanks a lot in advance. Best Regards, Marconi (1 Reply)
Discussion started by: marconi
1 Replies

4. UNIX for Dummies Questions & Answers

Checking file sizes in script

Hi, I'm trying to check a filesize within a script and then excute a relevant action. An example is below: if then rm $filename rm $filename2 elif then rm $filename2 fi Basically if $filename2 has a filesize of 0 then I want both files to be removed, but... (6 Replies)
Discussion started by: chris01010
6 Replies

5. Shell Programming and Scripting

Checking ksh script syntax

To check a bash script syntax without executing it we use: bash -n scriptname What should be the equivalent command for checking a ksh script? (8 Replies)
Discussion started by: proactiveaditya
8 Replies

6. Shell Programming and Scripting

Script check for file, alert if not there, and continue checking until file arrives

All, Is there a way to keep checking for a file over and over again in the same script for an interval of time? Ie If { mail -user continue checking until file arrives file arrives tasks exit I don't want the script to run each time and email the user each time a file... (4 Replies)
Discussion started by: markdjones82
4 Replies

7. Shell Programming and Scripting

Help with script checking for a file in various servers

I am trying to write a script that checks whether or not, a file exists on multiple servers. My code / logic so far is: #!/usr/bin/ksh print "Enter File name to be checked" read MYFILE ssh server1 " cd /var/opt/logs ; if then ... (4 Replies)
Discussion started by: momin
4 Replies

8. Shell Programming and Scripting

File checking script need help

Hi, Gurus, I need a scripts to check specified file if it exists or not at certain time (say every month between 5th and 7th). if file exists do something otherwise do another thing. can anybody help this? Thanks in advance :wall: (3 Replies)
Discussion started by: ken002
3 Replies

9. Shell Programming and Scripting

Checking LB status.. stuck in script syntax of code

#!/bin/ksh #This script will check status of load balancer in AIX servers from hopbox #Steps to do as folows : #Login to server #netstat -ani | grep <IP> #check if the output contains either lo0 OR en0 #if the above condition matches, validation looks good #else, send an email with impacted... (7 Replies)
Discussion started by: vinil
7 Replies

10. Shell Programming and Scripting

Command script for checking a file existence

Hello, I have a directory where sometimes appear a certain file name - and I'd like to be notified by email when that happens... so what command or script I may use? e.g. if there's a file named "adam" in the directory named "dir1" then send a mail to "abc@abc.com".. it needs to permanently... (5 Replies)
Discussion started by: netrom
5 Replies
All times are GMT -4. The time now is 09:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy