cron job problem, passing a parm


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cron job problem, passing a parm
# 1  
Old 03-09-2007
Data cron job problem, passing a parm

Hi,

I have an existing cron job like the following.

15 5 * * * /appl/scripts/MyScript.sh 2>/dev/null >/dev/null

and this works just fine.

Now I had to modify the script and now it requires an input parm as 2.

I had modified the cron entry so that the script can run now with the parm=2.

My new cron entry is below.

15 5 * * * /appl/scripts/MyScript.sh 2 2>/dev/null >/dev/null

Now the script is failing with a complaint that it could not find the input parm.

Any ideas ? on how to get around this problem.

Any help is appreciated.

Thanx..
-Bheem
# 2  
Old 03-09-2007
Quote:
Originally Posted by bheemsen
Hi,

I have an existing cron job like the following.

15 5 * * * /appl/scripts/MyScript.sh 2>/dev/null >/dev/null

and this works just fine.

Now I had to modify the script and now it requires an input parm as 2.

I had modified the cron entry so that the script can run now with the parm=2.

My new cron entry is below.

15 5 * * * /appl/scripts/MyScript.sh 2 2>/dev/null >/dev/null

Now the script is failing with a complaint that it could not find the input parm.

Any ideas ? on how to get around this problem.

Any help is appreciated.

Thanx..
-Bheem
The cron entry is specified correct. Therefore the problem seems to be within the script.

To tell what is going wrong there we would have to see the script.
# 3  
Old 03-09-2007
When I run the script from command prompt, it runs fine.

MyScript.sh 2

Inside the script I am assigning $1 to a variable and using that to pass to a stored procedure.

I tried the following cron entries too, but none worked.

15 5 * * * /appl/scripts/MyScript.sh '2' 2>/dev/null >/dev/null

15 5 * * * /appl/scripts/MyScript.sh "2" 2>/dev/null >/dev/null

15 5 * * * /appl/scripts/MyScript.sh \2 2>/dev/null >/dev/null
# 4  
Old 03-11-2007
Quote:
Originally Posted by bheemsen
When I run the script from command prompt, it runs fine.

MyScript.sh 2

Inside the script I am assigning $1 to a variable and using that to pass to a stored procedure.

I tried the following cron entries too, but none worked.

15 5 * * * /appl/scripts/MyScript.sh '2' 2>/dev/null >/dev/null

15 5 * * * /appl/scripts/MyScript.sh "2" 2>/dev/null >/dev/null

15 5 * * * /appl/scripts/MyScript.sh \2 2>/dev/null >/dev/null
Like I said, the mistake is inside the script.

But since you clearly don't want to show it, you can't be helped.

The parameter itself is not the problem.
# 5  
Old 03-12-2007
Can you run the script as standalone successfully without cronjob. That way, atleast we know, it's not script problem
# 6  
Old 03-12-2007
Hi roopla and sb008,

As I said earlier, there was no problem in the script. I could run it successfully as a standalone script.

Here is my complete script:
-------------------------------------------------
#!/usr/bin/ksh
. ~/.profile # for cron job environment visibility

filedate=`date +%m%d%H`
LogPath=/appl/loopqual/ait/log
Log=$LogPath/MyScript_$filedate.log
logtime=`date +%H%M%S`
echo "MyScript.sh started $logtime\n" > $Log

endmsg()
{
logtime=`date +%H%M%S`
echo "\nMyScript.sh end" $logtime >> $Log
exit 0
}

if [ $# -ne 1 ]
then
echo "Missing input parmameter\n" >> $Log
endmsg
fi
delete_agedmlr()
{
echo "Execute spDeleteAgedMlr" >> $Log
/appl/loopqual/ait/scripts/run_sp_2op.sh spDeleteAgedMlr W$1 delete_agedmlr

if [[ $? -ne 0 ]]
then
echo "spDeleteAgedMlr failed\n" >> $Log
fi
echo "spDeleteAgedMlr completed\n" >> $Log
}

delete_agedmlr $1
endmsg
sync
----------------------------------------------
Here is the output (from log file) when I ran it from cron.

MyScript.sh started 105331

Missing input parmameter


MyScript.sh end 105331

---------------------------------------------
Here is the output (from log file) when I ran it from command prompt.

$MyScript.sh 2

MyScript.sh started 105856

Execute spDeleteAgedMlr
spDeleteAgedMlr completed


MyScript.sh end 105857
------------------------------------------------

I do not understand what is going on here and why the script is not able to find the input parmater from cron entry.

Please help!!!!
Thanx..
-Bheem
# 7  
Old 03-12-2007
I'm guessing that the command line in cron is reading all your redirection (to /dev/null) as parameters.

Either don't test for the number of passed parameters (get rid of the $# test), check that the number of passed parameters is greater than 0, or just check that $1 is a valid parameter.

Oh, and set the $1 variable early, not late, in case the $1 value is changed before you use it later on in your script.

That's my guess...

Actually, I'm not seeing where you set the variable to the contents of $1. Am I missing something?

Last edited by [MA]Flying_Meat; 03-12-2007 at 04:40 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execution problem with CRON job

HI, I have written an executable file in unix and I was able to execute it successfully but when I called this file with cron job it was giving error like "permission denied" and "No such file or directory". Please help in how cron calls the file and what permission is required on the file... (2 Replies)
Discussion started by: vipin kumar rai
2 Replies

2. Solaris

Problem with a cron job

When i am trying to open crontab throught command crontab -e. It is not opening? OUTPUT: # crontab -e sh: vim: not found The crontab file was not changed. Please let me know how to open and edit it??? (10 Replies)
Discussion started by: kkalyan
10 Replies

3. UNIX for Dummies Questions & Answers

Cron job problem

I have a perl script which Im planning to run every minute. I have set the cron job as * * * * * PATH= /usr/local/bin:/usr/bin:/usr/sbin:/usr/lib; perl /dm2/www/html/isos/pre5.3/autoDownload.pl I assume the script is executing every minute only because I see a entry like below when I do... (2 Replies)
Discussion started by: srijith
2 Replies

4. Shell Programming and Scripting

Problem with Cron job

Hi , I have a TCL script which i am supposed to run as a cron job.. The script works fine from command line , but when run as a cron job , its unable to find a package,, my crontab is as follows. --------------------------- #!/usr/bin/ksh * * * * * PATH=/cm8/auto/Automation/Library/TclLib ... (7 Replies)
Discussion started by: Sudharshana
7 Replies

5. UNIX for Dummies Questions & Answers

Problem running a cron job

I have created a cron job for the vtiger workflow to execute the shell file named com_vtiger_workflow.sh to run the workflow. I've created the following line in crotab -e : 00 13 * * * /var/www/html/prashant/cron/modules/com_vtiger_workflow/com_vtiger_tiger_workflow.sh | mail -s 'Check... (2 Replies)
Discussion started by: anaigini45
2 Replies

6. Shell Programming and Scripting

Scheduling Cron job-Problem

Hello All, I want to run a script for every 5 minutes interval.So i developed a script which has to be scheduled to run for every 5 minutes. That script internally runs another script. But the problem is it is not executing properly. Can anybody throw some light on this. Below are the code... (4 Replies)
Discussion started by: RSC1985
4 Replies

7. Shell Programming and Scripting

Passing the value of Out parm in SP to UNIX Shell Script

I have a simple procedure which accepts two input parms and returns and output count: CREATE OR REPLACE Procedure GET1 ( IN_FOLDER IN VARCHAR2, IN_SUBJECT_AREA IN VARCHAR2, OUT_CNT IN OUT VARCHAR2 ) AS BEGIN ... (2 Replies)
Discussion started by: Hangman2
2 Replies

8. Solaris

problem with cron job

new to unix here, im learning how to schedule jobs with crontab. The following cron job runs under root but not under a test account i created. 50 11 * * 0 /usr/bin/banner "HELLO" > /dev/console i have no idea with it isn't running under the test account but runs right on time when i create... (7 Replies)
Discussion started by: solne
7 Replies

9. Solaris

cron job problem

I am trying to setup cronjob and once I start to save it is not working. This is what I am getting after I executed crontab -e, I am not even getting the privious entry and I am running from root. crontab -e 421 10 3 * * * /usr/sbin/logadm ? :wq ? Why is it not saving? Any input is... (4 Replies)
Discussion started by: mokkan
4 Replies

10. Shell Programming and Scripting

Script to submit a job with date parm in maestro

I'm a newbie in scripting attempting to create a script where i can submit a job (in maestro/tivoli) with parameters,in maestro CLI i can do that no problem,i'm thinking about creating a script that will accept input while the script is executing, more like below structure: exec the script -... (1 Reply)
Discussion started by: Kirojin
1 Replies
Login or Register to Ask a Question