issue invoking shell script using cron, even with proper file permission


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting issue invoking shell script using cron, even with proper file permission
# 1  
Old 11-02-2009
issue invoking shell script using cron, even with proper file permission

I am using tcsh

what could possibly be a problem, when using crontab to invoke a shell script. ?

The script has the read, write and execute permission to all users. And the script works as expected while executing it in stand-alone mode.

Is there a way to trace (like log) what error cron scheduler faces while trying to invoke the shell script ?

Myscript.ksh
#!/bin/ksh
`echo date >ech.txt`

my cron entry
21 11 30 * * /pkgs/roots/scripts/Myscript.ksh
# 2  
Old 11-02-2009
you are missing absolute path for the file where you are redirecting.

you should give something like,
Code:
>/tmp/output

# 3  
Old 11-02-2009
You're not using tcsh. You're using ksh.

Errors normally go to the mailbox of whoever runs the job.

Perhaps you could say /bin/date, instead of just date.

(as well as thegeek's suggestion about the output path)
# 4  
Old 11-02-2009
i tried giving absolute path for redirection. But it didn't work.

i also tried to giving the cron entry
21 11 30 * * /pkgs/roots/scripts/Myscript.ksh 2>&1 > /pkgs/roots/scripts/tempfile.txt

However i just got an empty file(tempfile.txt) created at the scheduled time.
# 5  
Old 11-02-2009
Why are you actually doing this:

Code:
`echo date > ech.txt`

when

Code:
date > ech.txt

would do?

Date is quite capable of executing and echoing itself without help (unless you mean to echo the literal string "date" to a file, that is)

in which case
Code:
echo date > echo.txt

would suffice.
# 6  
Old 11-02-2009
The backticks are not required in this context and cause the script to be unpredicatable whether run from the command line or from cron. Also the "echo" is probably not required if you want to get the current date into file ech.txt.

Code:
#!/bin/ksh
date > ech.txt

From your later post.
Quote:
21 11 30 * * /pkgs/roots/scripts/Myscript.ksh 2>&1 > /pkgs/roots/scripts/tempfile.txt
The script does not output anything which is why tempfile.txt is empty. Any syntax errors etc. will be in unix mail for the user issuing the cron.

The cron will of course only execute when it is 11:21 on the 30th of the month.

Last edited by methyl; 11-02-2009 at 12:09 PM.. Reason: Typo. Afterthought,
# 7  
Old 11-02-2009
using cron to call a script from another script

Quote:
Originally Posted by methyl
The backticks are not required in this context and cause the script to be unpredicatable whether run from the command line or from cron. Also the "echo" is probably not required if you want to get the current date into file ech.txt.

Code:
#!/bin/ksh
date > ech.txt

From your later post.

The script does not output anything which is why tempfile.txt is empty. Any syntax errors etc. will be in unix mail for the user issuing the cron.

The cron will of course only execute when it is 11:21 on the 30th of the month.

Hi All,
Thanks a lot for all your help.

I tried to invoke Myscript from another script. And i put the calling script(call_Myscript.ksh) in the cron. But in the log(tempfile.txt) i jus get the echo before the script invocation only. None of the echo in Myscript.ksh
goes to the log. both script file permissions are 777.

Can u please help me find what's wrong in this..?

Script 1: /pkgs/roots/scripts/Myscript.ksh

Code:
 #!/bin/ksh
 echo "script execution starts" >> tempfile.txt
 DAY=`date +%j`
 echo "JUL_DT is $DAY" >> tempfile.txt
 echo "script execution completes" >> tempfile.txt

Script 2: /pkgs/roots/scripts/call_Myscript.ksh
Code:
 #!/bin/ksh
 echo "calling the script" >> tempfile.txt
 /pkgs/roots/scripts/Myscript1.ksh
 echo "script completed successfully" >> tempfile.txt

cron entry
Code:
55 07 30 * * /pkgs/roots/scripts/call_Myscript.ksh 2>&1 >/pkgs/roots/scripts/tempfile.txt


what is the proper way to call a script from another script ?

Last edited by vgersh99; 11-02-2009 at 12:51 PM.. Reason: code tags, please!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Invoking Application in Shell Script

Hi All, I have a scenario : 1. A list of servers naming server21, server 22, server 23 etc. This list of servers is separate for my environments. Env1 has 3 server Env2 has 5 serves Env3 has 10 servers 2. Each server accesses application through which I want to invoke some method. So... (7 Replies)
Discussion started by: ankur328
7 Replies

2. Shell Programming and Scripting

Problem invoking shell script

whats wrong here?! ________________ #!/bin/sh # FILE: clean_dirs # GOAL : To clean up directories used in Oracle processing # LANGUAGE : shell script (sh) # PARAMETERS : Input_File # 11/07/02 acri - modified to cd into the directory so it will... (7 Replies)
Discussion started by: gillraj
7 Replies

3. Infrastructure Monitoring

Proper permission /etc/snmp/snmpd.conf

Hi All, I'm hardening my linux. And I came across with this file. /etc/snmp/snmpd.conf It's current mod is 644 with root:root ownership and group. Can I make this 640 without hurting the OS? Meaning no public read access. Does other resources need to read to it? Thanks and more... (1 Reply)
Discussion started by: itik
1 Replies

4. Shell Programming and Scripting

Invoking one shell script from another unix box

Hello All, I have a shell script A which is in one unix box. Also i have a script B in another unix box. Now i'm struggling to find a way to invoke A shell script from B shell script. Is it possible to do this in any way..Request you anybody please help me in this point. Thanks in advance. (6 Replies)
Discussion started by: RSC1985
6 Replies

5. UNIX for Advanced & Expert Users

Invoking shell script with perl command.

Hi All, I am using the following command to invoke the shell script from a perl command. perl -i.bak -pe'BEGIN { $cmd = "/opt/coreservices/tomcat-5.5.9/bin/digest.sh -a sha"; } s/(password=")(*)/ $1.`$cmd $2|cut -d: -f2|tr -d "\n"` /e ' $CATALINA_HOME/conf/tomcat-users.xml I need... (1 Reply)
Discussion started by: nua7
1 Replies

6. Shell Programming and Scripting

invoking a shell script inside cgi shell script

Hi, I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input. I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (2 Replies)
Discussion started by: smriti_shridhar
2 Replies

7. Shell Programming and Scripting

Shell script for accessing a file in the network drive and invoking oracle sql loader

Hi, Please let me know if anybody is having a solution handy for the below tasks... It would be helpful if somebody can resolve my query. I am new to unix and oracle environment and looking for some online reference for completing a task. Task: Check if the network drive exists Check... (0 Replies)
Discussion started by: sayydevara
0 Replies

8. Shell Programming and Scripting

Invoking Shell Script via php

list me commands to invoke a shell script from php once the submit button is clicked in the php page. Requirement is Once a submit button is clicked it should run a script that displays the outcome of the script in a html/php. Please help. Thanks in Advance, BubeshJ (2 Replies)
Discussion started by: bubeshj
2 Replies

9. Shell Programming and Scripting

invoking one shell script from other

hi, i am one day old in shell scritpting. how to invoke one shell script from the other? For eg.i have two shell scripts A.sh and B.sh. Inside A.sh i need to invoke B.sh and the return code of A.sh should be the value returned by B.sh. it would be better if you provide any sample shell... (3 Replies)
Discussion started by: ajay xavier
3 Replies

10. Shell Programming and Scripting

Wrong Shell Invoking My Script On Linux

I have a shell script that does NOT have the '#!' line at the top. It is written for ksh. The shell in my passwd entry is '/usr/bin/ksh' and my SHELL env variable is '/usr/bin/ksh'. Now, here's the issue. I invoke the script on Solaris with './myprog'. This works fine. I also run the same... (3 Replies)
Discussion started by: kowrip
3 Replies
Login or Register to Ask a Question