Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Test if script was ran w/ nohup Post 302729663 by Don Cragun on Saturday 10th of November 2012 07:56:50 PM
Old 11-10-2012
Inside a shell script it is hard to determine if it was started by the nohup utility. However, if STDOUT or STDERR for your script is a TTY device, you will know that it was not started by nohup. If being immune to SIGHUP signals and not having STDOUT directed to a TTY device and not having STDERR directed to a TTY device is sufficient for your script to continue running, the following code may help:
Code:
#!/bin/ksh
trap '' HUP
if [ "x$(tty <&1)" != "xnot a tty" ] || [ "x$(tty <&2)" != "xnot a tty" ]
then    printf '%s: This script must be started by "nohup %s ..."\n' "$0" "$0"
        exit 1
fi
printf '%s SIGHUP ignored and STDIN & STDERR directed to non-TTYs\n' "$0"
. . . other shell commands . . .

This was written and tested with the Korn shell, but should work with bash, ksh, or sh with no changes. It won't work with csh or similar shells.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reg: Shell script ran using informatica

Hi all, I am not sure whether this is the right place to ask this question...:) I am working in Informatica PowerCenter 8.1.1 tool and my server is on UNIX. I have got a shell script to copy files from one folder to another. When I run the script directly from UNIX prompt it is taking 60... (0 Replies)
Discussion started by: sam99
0 Replies

2. Shell Programming and Scripting

Script to ran ant.xml file

Hi All, I want to login to Oracle Application Server and run ant.xml file. Can someone propose a script for that task? Thanks, Abraham123 (0 Replies)
Discussion started by: Abraham123
0 Replies

3. Shell Programming and Scripting

nohup command in the script....

I want to know how to use a nohup command in the script........ I have to run following command nohup /tmp/app/statuscheck.sh & After typing this command I will type ctrl D to come to the prompt and the that command will run in backround. Even after pressing & the command is not... (3 Replies)
Discussion started by: jayaramanit
3 Replies

4. UNIX for Dummies Questions & Answers

Script ran by job scheduler fails from the 15th to the 20th of the month

Hi, I have a script that finds the application logs from the previous day and sends it to another server via ftp. The code is something like this: yest_date=`TZ=CST+24 date "+%b %d"` logdir=/app/logs logs=app*.log tmpdir=/tmp cd $logdir for i in `ls -1 $logs` do chkstr=`ls -1l $i | grep... (2 Replies)
Discussion started by: tatchel
2 Replies

5. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

6. Shell Programming and Scripting

absolute path for a script ran with relative path

I have a script in which i want to print absolute path of the same script irrespective of path from where i run script. I am using test.sh: echo "pwd : `pwd`" echo "script name: $0" echo "dirname: `dirname $0`" when i run script from /my/test/dir/struct as ../test.sh the output i... (10 Replies)
Discussion started by: rss67
10 Replies

7. Shell Programming and Scripting

how to find whether a script ran or not

Hi, I have written a script and placed in an application and the script can be executed manually only. But somehow one of the method in the script is being called and bringing the application down. But we are not able to find any instance of script running. Is there a way to findout whether the... (1 Reply)
Discussion started by: Satyak
1 Replies

8. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

9. Shell Programming and Scripting

Saving nohup output to a file other than nohup.out

Shell : bash OS : Oracle Linux 6.4 I want to save the ouput of a nohup command to file other than nohup.out . Below are my 3 attempts. For both Attempt1 and Attempt2 , the redirection logs the output correctly to the output file. But I get the error "ignoring input and redirecting stderr to... (7 Replies)
Discussion started by: kraljic
7 Replies

10. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies
TTY(4)							     Linux Programmer's Manual							    TTY(4)

NAME
tty - controlling terminal DESCRIPTION
The file /dev/tty is a character file with major number 5 and minor number 0, usually of mode 0666 and owner.group root.tty. It is a syn- onym for the controlling terminal of a process, if any. In addition to the ioctl(2) requests supported by the device that tty refers to, the ioctl(2) request TIOCNOTTY is supported. TIOCNOTTY Detach the calling process from its controlling terminal. If the process is the session leader, then SIGHUP and SIGCONT signals are sent to the foreground process group and all processes in the current session lose their controlling tty. This ioctl(2) call only works on file descriptors connected to /dev/tty. It is used by daemon processes when they are invoked by a user at a terminal. The process attempts to open /dev/tty. If the open succeeds, it detaches itself from the terminal by using TIOCNOTTY, while if the open fails, it is obviously not attached to a terminal and does not need to detach itself. FILES
/dev/tty SEE ALSO
chown(1), mknod(1), ioctl(2), termios(3), console(4), tty_ioctl(4), ttyS(4), agetty(8), mingetty(8) COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2003-04-07 TTY(4)
All times are GMT -4. The time now is 12:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy