Detect if script starts from queue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Detect if script starts from queue
# 15  
Old 08-16-2012
Add redirect , then cron not send email.
Code:
* * * * *   /some/command  >/dev/null 2>&1

This User Gave Thanks to kshji For This Post:
# 16  
Old 08-16-2012
Quote:
Originally Posted by kshji
Add redirect , then cron not send email.
Code:
* * * * *   /some/command  >/dev/null 2>&1

Thank you, but I notice that the error stop the rest of the script as reported in my post. So the problem is not only the generated mail!
But probably you have replied before I modified my post! Smilie
# 17  
Old 08-16-2012
I did warn you there'd be error message spam. I also told you how to deal with that. Redirect stderr into /dev/null so the messages don't go into your cron mails, but save that FD for later before you do so so you can restore it afterwards.

Your code already does this kind of redirection, you appeared to know how to do so already. I'll show you again though.

Code:
CheckInteractive ()
{

exec 10<&2 # Make a copy in FD 10
exec 2>/dev/null

if exec 7</dev/tty
then
  bold=`tput bold`
  normal=`tput sgr0`
  echo ; echo "${bold}WARNING: SCRIPT cannot start from command line, use parameters instead (interactive mode)!${normal}"
  exit                 
fi

exec 2>&10 # Restore stderr
exec 10>&- # Close the copy
}

This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to detect url in use in a script?

Hello, I have a small script and it runs from web application in below format: pipe:///path_to_myscript.sh url1 url2 url3 myscript.sh: #!/bin/bash count=0 while do count=$((count+1)) exec 3>&1 ((ffmpeg -i $1 ...... -f mpegts pipe:1 2>/dev/null 1>&3 ) 2>&1 | \ while read LINE; do echo... (9 Replies)
Discussion started by: baris35
9 Replies

2. HP-UX

Script to detect time drift

Hello there, I am not an expert in networking related stuff but I got a requirement to create UNIX script to query our Company's internal time source via NTP for time drift detect and report it when > +/- 50ms. I have been googling a lot but thought to post it in this forum to get a... (17 Replies)
Discussion started by: Green_Star
17 Replies

3. UNIX for Advanced & Expert Users

A script to detect system type

Hi forum, So I am trying to determine the OS type with the following script: #!/usr/bin/sh OStype1=`uname -s` Sunos1=SunOs if then echo "This system is Linux" exit 0 elif then echo "This system is SunOs" exit 0 elif (1 Reply)
Discussion started by: dampio
1 Replies

4. Shell Programming and Scripting

Help with detect with regex and move script

Hi all, I am needing some help with a script that will search for a video file by known extensions and then do a pattern search (I'm guessing via regex) and then based on a match of one type of another move the file to an assigned directory. I would like to do this with either a shell script... (7 Replies)
Discussion started by: Simplify
7 Replies

5. Shell Programming and Scripting

Need to write a shell script that starts one, then kills it, then starts another?

This is on a CentOS box, I have two scripts that need to run in order. I want to write a shell script that calls the first script, lets it run and then terminates it after a certain number of hours (that I specify of course), and then calls the second script (they can't run simultaneously) which... (3 Replies)
Discussion started by: btramer
3 Replies

6. Homework & Coursework Questions

When I run the script, the cursor starts on the wrong line?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: It's a shell script using a looping logic, trap, tput, if, while. Most of the scripts in this book aren't written... (2 Replies)
Discussion started by: ckleinholz
2 Replies

7. UNIX for Advanced & Expert Users

Script to rename file that was generated today and which starts with date

hello, can someone please suggest a script to rename a file that was generated today and filename that being generated daily starts with date, its a xml file. here is example. # find . -type f -mtime -1 ./20130529_4995733057260357019.xml # this finename should be renamed to this format.... (6 Replies)
Discussion started by: bobby320
6 Replies

8. Shell Programming and Scripting

Start script when a user starts a remote session

Howdy, I'm fairly new at bash scripting, but (for some reason) I've been tasked with building a bastion server and logging all (ssh/telnet) remote activity. Each session must create a unique log file - the name of each file must include the user ID, the connection method (ssh/telnet), the name... (2 Replies)
Discussion started by: kilo90
2 Replies

9. UNIX for Dummies Questions & Answers

Why do a unix script starts with a comment?

For eg: #!/usr/bin/ksh <remaining code goes here> .. .. Does the compiler ignores that? Thanks (2 Replies)
Discussion started by: ajincoep
2 Replies

10. UNIX for Dummies Questions & Answers

how to detect my script is already running

I have a script which must not be run more than once at any given time. THis script will be scheduled to run every 20 mins as a cron job. In my script can i have logic to say if this script is already running from the previous cron, then exit. How do i go about doing that. If you describe the... (11 Replies)
Discussion started by: rmulchandani
11 Replies
Login or Register to Ask a Question