CRON: Script not getting invoked


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CRON: Script not getting invoked
# 1  
Old 04-12-2010
CRON: Script not getting invoked

Hi,
I have the following script -

Code:
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 [1|2|3|5] ? [1]:" $cc
  read ans
  case $ans in
    2) echo "1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * *" $fixpart >> myCron
       break ;;
    3) echo "1,4,7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * *" $fixpart >> myCron
       break ;;
    5) echo "1,6,11,16,21,26,31,36,41,46,51,56 * * * *" $fixpart >> myCron
       break ;;
    *) echo "* * * * *" $fixpart >> myCron ;;
  esac
  echo ""
 
crontab myCron


Now, I see that "myScript" is not getting executed although crontab -l lists the item. But, manually if I run the script like this - "./myScript", it runs properly.

So, there is no issues in "myScript". I guess, the problem is with setting up CRONjob. Probably, I am doing it wrong ?

Can anybody suggest what I am doing wrong or what should I do to run a script with above conditions?

Last edited by vgersh99; 04-12-2010 at 07:43 AM.. Reason: code tags, please!
# 2  
Old 04-12-2010
As always, search the forums and the FAQs first!
# 3  
Old 04-12-2010
The problem is more likely to be in one or more of these areas:

Code:
   Contents of "/file/MyScript".
         Assumptions about the environment (cron's is different from user).
         Relative file names.
         Missing "shebang" line meaning that you use cron's default shell.
         Script asks questions when there is no terminal?
   Permissions of "/file/MyScript".
         Executable?
   Permissions of the user.
         User allowed to use cron?
   Fundamental problem.
         cron daemon not running?

The error message is usually to be found in the unix mail for the user owning the cron.
To check whether the job ran at all see cron's own log (see "man cron" for location of the log).
# 4  
Old 04-15-2010
Quote:
Originally Posted by methyl
The problem is more likely to be in one or more of these areas:

Code:
   Contents of "/file/MyScript".
         Assumptions about the environment (cron's is different from user).
         Relative file names.
         Missing "shebang" line meaning that you use cron's default shell.
         Script asks questions when there is no terminal?
   Permissions of "/file/MyScript".
         Executable?
   Permissions of the user.
         User allowed to use cron?
   Fundamental problem.
         cron daemon not running?

The error message is usually to be found in the unix mail for the user owning the cron.
To check whether the job ran at all see cron's own log (see "man cron" for location of the log).
Hi,
I read the FAQ and went through your comments too. I am able to write a CRON and invoke a script. But the problem is output is not coming. The script getting invoked (sqlScript) is this -

Code:
echo "select empName from emp_tbl where emp_id = 5" | /usr/bin/sql emp_db 2>/usr/count_file | grep david > /usr/temp1

The cron is like this
Code:
* * * * * /usr/sqlScript

Now, when the cron runs, after a minute, count_file and temp1 are created empty. BUT,if I run the script from command line like ./sqlScript, then there is a single row value in the above files. Anything I am missing here ?

Last edited by angshuman_ag; 04-15-2010 at 08:27 AM..
# 5  
Old 04-16-2010
both are running under same user id & environment ?
# 6  
Old 04-16-2010
Quote:
Originally Posted by thegeek
both are running under same user id & environment ?
I just logged in as the normal system user and wrote the script under that user account only. But, I went to /var/spool/cron/crontabs directory and saw that the cron file created under the logged in user acc does not have even read permission, Whereas, other cron files like "sys" & "adm", have read-write permission. Is that the issue ? How do I fix this ?

Last edited by angshuman_ag; 04-16-2010 at 01:41 AM..
# 7  
Old 04-16-2010
I think you have to open crontab in edit mode by
crontab -e
then only you can do entry in it.
not posible with redirection symbol
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

3. 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

4. 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

5. Shell Programming and Scripting

Script invoked using "sh" is not executing. Urgent help required

Hi , I am new to shell scripting. I am using Linux for doing scripting. Below is my script, which takes 2 parameters as input. test.sh has the below: #!/bin/bash . $HOME/.profile gpg --yes --no-use-agent -r "$(eval echo \$$2_Var)" -e $1 1st parameter is command line... (7 Replies)
Discussion started by: rangarb
7 Replies

6. Solaris

expect package is not invoked from cron

Hi, I am running some etl commands in the windows from shell script(from unix sun solaris 5.9) by using expect package .While running manually the script is working fine.While running from cron it is exiting the after successfully firing the ETL command(The control does not stop after firing... (1 Reply)
Discussion started by: megh
1 Replies

7. 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

8. 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

9. 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

10. Shell Programming and Scripting

determine if the script has been invoked manually or not?

Hi, Is there a way to determine if the script has been invoked manually or not( might be invoked by a schedular or crontab)? Thanks, (8 Replies)
Discussion started by: hitmansilentass
8 Replies
Login or Register to Ask a Question