Sponsored Content
Top Forums Shell Programming and Scripting determine if the script has been invoked manually or not? Post 302117385 by radoulov on Monday 14th of May 2007 04:03:05 AM
Old 05-14-2007
You can check if the process is associated/connected to terminal.
For example this is with lsof on Linux:

Note the terminal devices (pts):

Code:
$ lsof -p 10716
COMMAND   PID   USER   FD   TYPE DEVICE     SIZE   NODE NAME
bash    10716 oracle  cwd    DIR  72,17     4096  32705 /app/oracle
bash    10716 oracle  rtd    DIR  253,0     4096      2 /
bash    10716 oracle  txt    REG  253,0   616248 393573 /bin/bash
bash    10716 oracle  mem    REG  253,0    45889 491876 /lib/libnss_files-2.3.4.so
bash    10716 oracle  mem    REG  253,0   106397 491564 /lib/ld-2.3.4.so
bash    10716 oracle  mem    REG  253,0  1454802 229472 /lib/tls/libc-2.3.4.so
bash    10716 oracle  mem    REG  253,0    15324 491856 /lib/libdl-2.3.4.so
bash    10716 oracle  mem    REG  253,0    12592 491892 /lib/libtermcap.so.2.0.8
bash    10716 oracle  mem    REG  253,0    21544 262456 /usr/lib/gconv/gconv-modules.cache
bash    10716 oracle  mem    REG  253,0 48504432 132692 /usr/lib/locale/locale-archive
bash    10716 oracle    0u   CHR  136,2               4 /dev/pts/2
bash    10716 oracle    1u   CHR  136,2               4 /dev/pts/2
bash    10716 oracle    2u   CHR  136,2               4 /dev/pts/2
bash    10716 oracle  255u   CHR  136,2               4 /dev/pts/2

This is from cron:

Code:
$ lsof -p 10673
COMMAND   PID   USER   FD   TYPE DEVICE    SIZE   NODE NAME
sleep   10673 oracle  cwd    DIR  72,17    4096  32705 /app/oracle
sleep   10673 oracle  rtd    DIR  253,0    4096      2 /
sleep   10673 oracle  txt    REG  253,0   17340 394503 /bin/sleep
sleep   10673 oracle  mem    REG  253,0   93985 229474 /lib/tls/libpthread-2.3.4.so
sleep   10673 oracle  mem    REG  253,0   47671 232047 /lib/tls/librt-2.3.4.so
sleep   10673 oracle  mem    REG  253,0  106397 491564 /lib/ld-2.3.4.so
sleep   10673 oracle  mem    REG  253,0 1454802 229472 /lib/tls/libc-2.3.4.so
sleep   10673 oracle  mem    REG  253,0  178019 229504 /lib/tls/libm-2.3.4.so
sleep   10673 oracle    0r  FIFO    0,7         267166 pipe
sleep   10673 oracle    1w  FIFO    0,7         267167 pipe
sleep   10673 oracle    2w  FIFO    0,7         267167 pipe

On Solaris with ptree:

Code:
$ ptree 29948
514   /usr/sbin/cron
  29939 sh -c /app/oracle/admin/xxxx/xxxxxx.ksh
    29948 /bin/ksh /app/oracle/admin/xxxx/xxxxxx.ksh
      72    ftp -i -n -v

You can play with pstree, strace (Linux), ptree, pfiles, truss (Solaris) as well.
And of course, I suppose there will be special cases.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can run script Manually, but not through Cron?

Hi all, I have a main script (called OracleCleanup) that runs some sql queries. that runs off a wrapper script which contains the sources for the login information and and JOB_HOME (the script is below). When I schedule this job in the cron the log says that it cannot open my list file, which... (4 Replies)
Discussion started by: MadHatter
4 Replies

2. Shell Programming and Scripting

check in unix shell script so that no one is able to run the script manually

I want to create an automated script which is called by another maually executed script. The condition is that the no one should be able to manually execute the automated script. The automated script can be on the same machine or it can be on a remote machine. Can any one suggest a check in the... (1 Reply)
Discussion started by: adi_bang76
1 Replies

3. Shell Programming and Scripting

Passing the values to the secondary script when it invoked by primary script

Hi, When I invoke a script s1.sh it will call an another script s2.sh by itself. This script s2.sh will call some java files, so while running the script it asks for a file name to be processed. Which we can see in the screen. The file name to be processed is present in script s1.sh Now... (1 Reply)
Discussion started by: venu_eie
1 Replies

4. UNIX for Advanced & Expert Users

Passing the values to the secondary script when it invoked by primary script

Hi, When I invoke a script s1.sh it will call an another script s2.sh by itself. This script s2.sh will call some java files, so while running the script it asks for a file name to be processed. Which we can see in the screen. The file name to be processed is present in script s1.sh Now I... (2 Replies)
Discussion started by: venu_eie
2 Replies

5. UNIX for Advanced & Expert Users

why the script name not displayed and not sh invoked?

Say there is a shell script named test.sh. I intentionally omit the #! line in test.sh for testing perpose. I did the following : $ echo $0 -ksh ---> current shell $ echo $$ 12919 ---> PID of the current shell... (4 Replies)
Discussion started by: hongwei
4 Replies

6. Shell Programming and Scripting

CRON: Script not getting invoked

Hi, I have the following script - fixpart="/files/myScript # Transfer Script" echo "Specify the transfer frequency in minutes - " echo "every 1, 2, 3, or 5 minutes (default every 1 minute) " echo $nn "Frequency ? :" $cc read ans case $ans in 2) echo... (9 Replies)
Discussion started by: angshuman_ag
9 Replies

7. Shell Programming and Scripting

How to ensure a script can only be invoked from another?

Hi All, I have two scripts - ScriptA and ScriptB ScriptA has logic to invoke ScriptB : - with some parameter - or without any parameter ScriptB can also be invoked by the user from the command line. Is there anyway to ensure that when I execute ScriptB from the command line, it does... (3 Replies)
Discussion started by: chaitanya.gvc
3 Replies

8. Shell Programming and Scripting

Problem with script invoked from a keyboard shortcut

-EDIT- I have solved my problem below by using a different program. Instead of xsel I am using xclip which basically does the same thing and works fine from a script invoked by a global hotkey. -END EDIT- Hi, I've written a simple script to copy my email address into both the... (0 Replies)
Discussion started by: gencon
0 Replies

9. Shell Programming and Scripting

Oracle function invoked from shell script doubt

hi gurus, I have tried myself to invoke an oracle function. there are three different function available need to be called for differnt. can you tell me whether the below code is correct to call oracle function from shell script. Any help would be highly appreciated. cat location.sh ... (5 Replies)
Discussion started by: arun888
5 Replies

10. Shell Programming and Scripting

Script runs manually, but not from cron

Hi, I "borrowed" a script I found online, to start a SAP router application on a Solaris 11 (SPARC) server. The script runs fine when calling it manually, but when I schedule it to run from cron, it doesn't. I don't see any warning or failure messages anywhere, just nothing happens. ... (11 Replies)
Discussion started by: bredman
11 Replies
ptree(1)																  ptree(1)

NAME
ptree - print process trees SYNOPSIS
/usr/bin/ptree [-a] [-c] [-z zone] [pid | user] ... ptree prints the process trees containing the specified pids or users, with child processes indented from their respective parent pro- cesses. An argument of all digits is taken to be a process-id, otherwise it is assumed to be a user login name. The default is all pro- cesses. The following options are supported: -a All. Print all processes, including children of process 0. -c Contracts. Print process contract memberships in addition to parent-child relationships. See process(4). This option implies the -a option. -z zone Zones. Print only processes in the specified zone. Each zone ID can be specified as either a zone name or a numerical zone ID. This option is only useful when executed in the global zone. The following operands are supported: pid Process-id or a list of process-ids. ptree also accepts /proc/nnn as a process-id, so the shell expansion /proc/* can be used to specify all processes in the system. user Username or list of usernames. Processes whose effective user IDs match those given are displayed. Example 1: Using ptree The following example prints the process tree (including children of process 0) for processes which match the command name ssh: $ ptree -a `pgrep ssh` 1 /sbin/init 100909 /usr/lib/ssh/sshd 569150 /usr/lib/ssh/sshd 569157 /usr/lib/ssh/sshd 569159 -ksh 569171 bash 569173 /bin/ksh 569193 bash The following exit values are returned: 0 Successful operation. non-zero An error has occurred. /proc/* process files See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ |Interface Stability |See below. | +-----------------------------+-----------------------------+ The human readable output is Unstable. The options are Evolving. gcore(1), ldd(1), pargs(1), pgrep(1), pkill(1), plimit(1), pmap(1), preap(1), proc(1), ps(1), ppgsz(1), pwd(1), rlogin(1), time(1), truss(1), wait(1), fcntl(2), fstat(2), setuid(2), dlopen(3C), signal.h(3HEAD), core(4), proc(4), process(4), attributes(5), zones(5) 11 Oct 2005 ptree(1)
All times are GMT -4. The time now is 05:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy