- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell quesition: How can I tell whether scrip...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2002 05:33 AM
тАО07-30-2002 05:33 AM
I've got a menu script that goes into a loop if the script inadvertantly runs in background mode. I suspect the connection is being lost in a citrix session.
I want to put in a code check that will terminate the script if it is not currently interactive.
Perhaps the following will be sufficient?
BASENAME=`/usr/bin/basename $0`
ps -ef | grep " $$ " | grep $BASENAME | grep -v "ps -ef" | grep -v grep | grep "?"
jack...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2002 05:47 AM
тАО07-30-2002 05:47 AM
Solutionif [ `tty | grep not | wc -l` = 1 ];
then
export BACKGROUND=YES
else
export BACKGROUND=NO
fi
This checks to see if there's a controlling tty for the job - if not, assume that it's running in the background (eg. via cron).
the $BACKGROUND parameter can then be used to exit/continue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2002 05:49 AM
тАО07-30-2002 05:49 AM
Re: shell quesition: How can I tell whether script is running in background?
if [[ -t 3 ]] ; then
echo "I am running in interactive"
else
echo "I am running in batch"
fi
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2002 05:58 AM
тАО07-30-2002 05:58 AM
Re: shell quesition: How can I tell whether script is running in background?
This will be good as you are trying to check on the current terminal session and then of course
export A=`ps -ef | grep " $$ " | grep $BASENAME | grep -v "ps -ef" | grep -v grep | grep "?" `
kill -9 $A
Manoj Srivastava
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2002 05:59 AM
тАО07-30-2002 05:59 AM
Re: shell quesition: How can I tell whether script is running in background?
PID=A PPID=B -sh
PID=C PPID=A -sh
PID=D PPID=C $BASENAME
So i should be possible to look whether or not the shell running the program was forked or not. In case the shell was forked, you program is running in backupground.
Hope it will help you.
Regards,
Ceesjan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2002 06:17 AM
тАО07-30-2002 06:17 AM