why Cron behaves different ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting why Cron behaves different ?
# 1  
Old 11-03-2010
why Cron behaves different ?

Hi,

i have script called script.ksh

script.ksh
---------
Code:
echo "Narayana" >$HOME/script.log
echo "$0" |sed 's/.ksh//' >>$HOME/script.log

My question is:
--------------
when iam executing on the prompt it is giving good results what we have expected...

example on the prompt:
-----------------------
Code:
 
sh -x script.ksh

output:
Code:
Narayana
script

example scheduling in cron:
--------------------------
Code:
* * * * * sh -x $HOME/Narayana/script.ksh 2> /tmp/script_cron.log >&2

output:
Code:
Narayana
/apps/t1twsat/Narayana/script

So, could you please tell me... why this happened... any clue to overcome this...

Thanks in advance

Last edited by Scott; 11-03-2010 at 08:29 AM.. Reason: Please use code tags
# 2  
Old 11-03-2010
You assume that cron will nicely cd to the directory where your script is?

The script will run from your home directory, and is run as specified in your crontab.

i.e.
Code:
$HOME/Narayana/script.ksh

$0 is the path to the script.

Code:
echo "Narayana" >$HOME/script.log
echo ${0##*/} >>$HOME/script.log

Another option is to do the cd in your cron definition:

Code:
* * * * * cd $HOME/Narayana; sh -x script.ksh 2> /tmp/script_cron.log >&2


Last edited by Scott; 11-03-2010 at 08:43 AM..
# 3  
Old 11-03-2010
Another comment, why are you giving your script the ".ksh" extension but executing it with a different shell, /bin/sh ?
# 4  
Old 11-03-2010
scottn :thanks a lot...

jlliagre: thanks... but i have just written as example
# 5  
Old 11-03-2010
I just wanted you to understand the "#!/bin/ksh" line was useless in both of your calls. You can use
Code:
ksh -x script.ksh ...

instead.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

'Connect' behaves differently on Solaris 11

Our application fails to run successfully on Solaris 11. The same works fine in Solaris 10. Due to which we are unable to migrate to Solaris 11. The app basically involves forking a child process, which finally connects with parent process. But on Solaris 11, it is unable to connect with parent... (0 Replies)
Discussion started by: wini008
0 Replies

2. Shell Programming and Scripting

Copy-pasted code behaves diffrent

Heyas I'm currently attempting to apply the code of tui-select to tui-list. That is because tui-list simply made a 1 string list, while tui-select uses dynamicly up to 3 strings per line. Anyway, so i copy pasted the code, and just made the changes marked with red.... Know that both scripts... (2 Replies)
Discussion started by: sea
2 Replies

3. Shell Programming and Scripting

Grep behaves diffrent upon printf or echo output

Hello I want to check whether certain arguments were passed to the script, and when those are, not doing a log entry. If those arguments are not passed, always do a log entry (*new call*). What currently i have is this: echo "${@}"|grep -q \\- || \ tui-log -e "$LOG" "\r---- New call $$... (4 Replies)
Discussion started by: sea
4 Replies

4. Linux

Does a network switch behaves as webserver

Hi, I have a question on web servers and network switches. Why a network switch should support certificate management, that means generating public and private keys... installing a certificate etcetra. Regards Chaitanya. :b: (4 Replies)
Discussion started by: chaitus.28
4 Replies

5. Shell Programming and Scripting

su - user -c 'command' behaves differently

I notice that su - user (note with dash) brings in more of the user's environment than does su - user -c 'command'. For example, if root does an su - user, and types "umask" to the prompt, one umask is displayed; yet, if instead the command is su - user -c 'umask', the value is different. I thought... (2 Replies)
Discussion started by: drokerm
2 Replies

6. Shell Programming and Scripting

Executing a script from CRON behaves differently than terminal

Hi have a script which transferers from Microsoft server to Linux box. The scripts(ksh) is on Linux box. If I run script from terminal, it transfers files to directory. Where as If I run script from CRON. It does not. Here is the log of both: Terminal execution log:... (2 Replies)
Discussion started by: dipeshvshah
2 Replies

7. Emergency UNIX and Linux Support

Functions defined in header / cpp file behaves different

File: A.h class A { public: struct x X; int show() { x.member_variable ? 0: -1; } }; Now if A.cpp is complied which includes A.h (which is actually in a huge project space) we see that x.member_variable value is not as expected. But if remove the show() method and place... (4 Replies)
Discussion started by: uunniixx
4 Replies

8. AIX

Command behaves different in script and on prompt

$cat /tmp/tuxob.lst udi ***** jim 10 ant 19 ibm ***** $ input=`head -1 /tmp/tuxob.lst | awk '{print $NF}'` $ echo $input The output I am expecting is '*****'. But It is showing me the available files of current directory. When I run the command head -1 /tmp/tuxob.lst | awk '{print $NF} ... (3 Replies)
Discussion started by: panchpan
3 Replies

9. Shell Programming and Scripting

mpack behaves abnormally

Hi, I was using mpack to send mails using cronjob with attachments. It was working perfect. But recently it's behaving strangely. Its sending the mails without any error message but the mail is not getting delivered. The code I was using: /usr/local/bin/mpack -s "$SUBJECT" -d $MSGBODY... (0 Replies)
Discussion started by: itesh.dash
0 Replies

10. Shell Programming and Scripting

Script behaves different when run from cron vs. manually

Hey all, Just wanted to get some input on a script I am using to import files into a MySQL database. The process is pretty simple: my main server exports these files and FTPs them. I have a script that FTPs them to the machine running that runs this script. The FTP script runs without issue... (2 Replies)
Discussion started by: billtwild
2 Replies
Login or Register to Ask a Question