so i have a script that i do not want copies of that script to be roaming around. i want that script to be in only one location on the filesystem, and whoever wants to use it should just link to it.
any idea on how to exit from a script if it is detected that the running version is a copy and not a link to the original??
Hi,
Another way would check inode file, examples:
my file:
Hard link of my file:
Symbolic link of my file:
A copy of my file:
inode's files:
here, inode of aa3.txt and aa4.txt are differents, but aa3.txt is a symbolic link, so with ls option "-L":
Now, just aa4.txt is different, but this is normal because it's a copy...
is limited to bash and ksh. The OP's script is a sh script:
Yes. Linux conflates bash and sh. That doesn't make such usage portable.
Let us be very clear here. When doing tests like this with a shell script, sometimes you have to know what shell you're using. Claiming that cd -P can't be used in /bin/sh might or might not be true. If you're using a Linux system where /bin/sh is a link to bash, you can use cd -P. If you're using a Solaris system where /bin/sh is a legacy Bourne shell, you can't use cd -P, but you can't use $(command) either (you'd have to use `command` instead).
Furthermore, the awk script shown in the code above is going to return an empty string any time $0 expands to an absolute pathname for the script being executed and . otherwise. That is the basis of the problem that kept the script from doing what the submitter intended to do. But..., as has been said before, I'm not sure that I understand this thread. If someone copies a script and slightly modifies it for some reason (any reason), modifying the original script to see if it has been moved doesn't help. Anybody that can copy and modify the script can obviously and easily also remove any code that verifies that the script hasn't been moved or modified.
is limited to bash and ksh. The OP's script is a sh script:
Yes. Linux conflates bash and sh. That doesn't make such usage portable.
This is not correct. cd -P is part of the POSIX standard. cd: Synopsis.
It also works with ksh88, so the only (Bourne family) shell it will not work with is the classic Bourne shell...
So cd -P is in fact very portable...
Also, as Don Cragun noted, the OP used $( ... ) so it is clear that the OP is not using classic Bourne shell and that #!/bin/sh points to a POSIX type shell.
----
Quote:
Originally Posted by Don Cragun
[..]But..., as has been said before, I'm not sure that I understand this thread. If someone copies a script and slightly modifies it for some reason (any reason), modifying the original script to see if it has been moved doesn't help. Anybody that can copy and modify the script can obviously and easily also remove any code that verifies that the script hasn't been moved or modified.
I agree as I noted in post #1. So if someone wants to circumvent this, it is very easy. The reason however, as I can see it, might be that you want to avoid a sprawl of the same script in a Company situation and to make users of the script aware that they should use the centrally maintained version by either using it directly or linking to it. If they want to bypass that, fine but then they should not complain if things break in the future..
Last edited by Scrutinizer; 01-04-2016 at 12:23 AM..
How can i tweak the below find command to exclude directory/s -> "/tmp/logs"
find . -type f \( ! -name "*.log*" ! -name "*.jar*" \) -printNote: -path option/argument does not work with the version of find that i have.
bash-3.2$ uname -a
SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v (7 Replies)
I was having trouble remembering the linux command to show where bin files are located. I eventually figured it out from googling that it was "which".
How to find command location in Linux?
Since I saw a few other interesting commands like whereis and type it got me curious. Are there any... (5 Replies)
This script writes the output files to FILES but I don't want to exclude all directories from ABC_CHQ and LYS_ADV, I want to include one sub directory name process which is under ABC_CHQ and LYS_ADV in the search. Right now its excluding everything from prune directories such as ABC_CHQ, LYS_ADV... (10 Replies)
Dear All,
I am using find command
find /my_rep/*/RKYPROOF/*/*/WDM/HOME_INT/PWD_DATA -name rk*myguidelines*.pdf -print
The problem i am facing here is find /my_rep/*/
the directory after my_rep could be mice001, mice002 and mice001_PO, mice002_PO
i want to ignore mice***_PO directory... (3 Replies)
I want to look if there is any file inside a specific directory which was modified before 2 days.
I wrote the find command, but the problem is there is one directory and that is a random directory generated by unix, so not sure on how to code for that on the find command.
find... (5 Replies)
i have this find command on my script as:
for i in `find $vdir -name "$vfile" -mtime +$pday`
the problem with this code is that the sub-directories are included on the search. how do i restrict the search to confine only on the current directory and ignore the sub-directories. please advise.... (7 Replies)
Hi All,
I'm trying to use the find command to return matches for a directory and file.
For example, given the following directories:
/one/two/three/file1.txt
/one/three/two/file1.txt
/one/four/two/three/file1.txt
I'm expecting the following to be returned:
... (16 Replies)
I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem.
so i need to use find command (6 Replies)
I am trying to use the find command to find files in the current directory that meet a certain date criteria.
find . -type -f -mtime +2
However, the above also checks the directories below.
I tried -prune, but that seems to ignore this directory completely.
I read about using -path w/... (5 Replies)