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
Forums
Discussions
Discussions
Discussions
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
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-04-2006 10:27 PM
07-04-2006 10:27 PM
Rgds.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2006 10:29 PM
07-04-2006 10:29 PM
Re: Cron
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2006 11:01 PM
07-04-2006 11:01 PM
Re: Cron
variation on Pete's suggestion:
Modify the actual cron call:
05 12 * * * export FROMCRON="cron";/a.sh > /a.lis 2>&1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2006 01:24 AM
07-05-2006 01:24 AM
SolutionI tried to insert this at the beginning of a script:
#!/usr/bin/sh
PARENT=$(UNIX95= ps -ef | grep $PPID | awk -v ppid=$PPID '$2 ~ ppid {print $3}')
CRON=$(UNIX95= ps -C cron | grep -v CMD| awk '{print $1}')
if [ $PARENT = $CRON ]
then
echo executed by cron
else
echo not executed by cron
fi
It seems to work on my system, but may not work anywhere else!
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2006 01:54 AM
07-05-2006 01:54 AM
Re: Cron
1) Link (hard) the normal version of the script and a cron version of the script.
e.g. normalscript.sh crnvrsionXY123.sh
Now your code simply tests ${0} to see which name was used to invoke the script.
Note that you intentionally make the cron'ed name difficult to use by including
deliberately obtuse characters.
2) Test stdin to see if it is a TTY device (ie, a terminal)
if [ -t 0 ]
then
echo "Interactive"
else
echo "Non-interactive; probably cron"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2006 07:53 AM
07-05-2006 07:53 AM
Re: Cron
I found this on the forums some time ago:
typeset INTERACTIVE=0 && [ -t 0 ] && INTERACTIVE=1
Put it in the beginning of the script to be executed, and then test 'INTERACTIVE'.
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2006 03:08 AM
07-06-2006 03:08 AM