Do not allow a script to run individually


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Do not allow a script to run individually
# 1  
Old 03-24-2010
Do not allow a script to run individually

Hi All,

I am having two scripts say scriptA.ksh and scriptB.ksh.

The scriptB.ksh should be executed only if it is called from scriptA.ksh. If someone tries to execute it individually from command prompt, the script should exit gracefully with appropriate message.

Any workarounds?

Thanks in advance.
# 2  
Old 03-24-2010
in scriptA.ksh call the scriptB.ksh with the some argument and check for that argument in scriptB.ksh and exit stating call the scriptA.ksh first..

Code:
$ cat a.sh
./b.sh M
$ cat b.sh
if [ "$1" != "M" ] ; then
        echo "Not called from A"
else
        echo "Called from A"
fi
$ ./a.sh
Called from A
$ ./b.sh
Not called from A
$


Last edited by pludi; 03-24-2010 at 06:30 AM.. Reason: an expert should know how to use code tags...
# 3  
Old 03-24-2010
This is a good solution. Thanks. However, I am looking for a solution where I don't have to change the parameters.
# 4  
Old 03-24-2010
$PPID contains the parent PID.

Code:
ps -p $PPID  -o "comm="

gives you the calling process name and path.
# 5  
Old 03-24-2010
Thanks Tony. This is what I was looking for. Can you please help me understanding -o "comm=" in below command?
# 6  
Old 03-24-2010
Please state what Operating System and version you have and what shell you use. Commands such as "ps" have different syntax on different Operating Systems ... and shell techniques vary from shell to shell.

An idea for a gash solution to your issue in any environment:
Create a flag file in the calling script and test for the presence of that file in the called script. If the flag file is not present the called script should exit gracefully, otherwise immediately delete the flag file and continue processing. (Purtists will note that there is a moment in time when someone could try to execute the called script from the command line. Also, someone with knowledge of the flag file name could create the file).
I depends on whether this is a security issue or basic accident prevention?
There will be better solutions using unix permissions.

Personally I'd pass an additional "activate" parameter as described by "expert". This method certainly protects against those who type "*" at the command line or those who type random commands.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Zipping multiple files individually

Team, I have files like below a1_test.csv a1_test2.csv a1_test3.csv wc -l >1 for all these files and if this condition is satisfied then the files should be zipped like a1_test.zip a1_test2.zip a1_test3.zip Please let me know how to do it in scripting. Thanks in advance. (6 Replies)
Discussion started by: weknowd
6 Replies

3. Shell Programming and Scripting

Script fails to run properly when run from CRONTAB

Hello all, I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly. My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Discussion started by: rusman
12 Replies

4. Shell Programming and Scripting

how to run an already made script run against a list of ip addresses solaris 8 question

how to run an already developed script run against a list of ip addresses solaris 8 question. the script goes away and check traffic information, for example check_GE-VLANStats-P3 1.1.1.1 and returns the results ok. how do I run this against an ip list? i.e a list of 30 ip addresses (26 Replies)
Discussion started by: llcooljatt
26 Replies

5. AIX

My script didn't run every run every minute at cronjob

In my cronjob, I would like to schedule my script.sh to run every minutes. I crontab -e and have in line below but it didn't seems to run at all. * * * * * script.sh When I run it manually, I can run it. Is that anything wrong with the above line? If I change it to something like below,... (4 Replies)
Discussion started by: ngaisteve1
4 Replies

6. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

7. Shell Programming and Scripting

while read loop w/ a nested if statement - doesn't treat each entry individually

Hi - Trying to take a list of ldap suffixes in a file, run an ldapsearch command on them, then run a grep command to see if it's a match, if not, then flag that and send an email alert. The list file (ldaplist) would look like - *********** o=company a o=company b *********** **... (7 Replies)
Discussion started by: littlefrog
7 Replies

8. UNIX for Advanced & Expert Users

script to run different shells which run different processes

Hi, Would like to ask the experts if anyone knows how to run a script like this: dtterm -title shell1 run process1 on shell1 dtterm -title shell2 run process2 on shell2 cheers! p/s: sorry if i used the wrong forum, quite concussed after watching world cup for several nights; but I... (2 Replies)
Discussion started by: mochi
2 Replies

9. Shell Programming and Scripting

Stop / kill the process individually

Hi , I have a situation, where I have 10 indivudal processess started by similar instance.I say similar instance because each of them being started as a new thread: Say I've following unix process running process1_ADAP process2_ADAP process3_ADAP Current scenario: Now I have SHUTDOWN... (5 Replies)
Discussion started by: braindrain
5 Replies
Login or Register to Ask a Question