Why does cron run this differently?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why does cron run this differently?
# 1  
Old 01-05-2003
Why does cron run this differently?

test.ksh
===================
#!/usr/bin/ksh

APPLICATION=hr_app
APPLICATION_UPPER=`echo $APPLICATION | tr [a-z] [A-Z]`

echo $APPLICATION_UPPER > /tmp/test.txt
echo $APPLICATION >> /tmp/test.txt
which tr >> /tmp/test.txt
===================
When I run this from the shell:
/home/natter> more /tmp/test.txt
HR_APP
hr_app
/usr/bin/tr

But when I run this from cron:

/home/natter> more /tmp/test.txt
hr_app
hr_app
/usr/bin/tr

Why isn't the tr command working when using cron?

Thanks in advance for any help.
# 2  
Old 01-05-2003
Are you redirecting STDERR and STDOUT to a log file for that cron job? Is there anything in there that might give you a hint? What OS is this?
# 3  
Old 01-05-2003
Solaris 2.8

STDERR and STDOUT don't show anything..

I just tried this on another unix box, and it worked fine. (2.8 box)..

Any clues on what to look for? I just can't figure this out.
# 4  
Old 01-06-2003
A command like:
echo abc*
might simply echo "abc*". Or the shell might find some filenames that match abc*, and it that case, it would echo the list of matching filenames.

Same deal with
echo [a-z]
the echo command may literally see "[a-z]". But if we have some one character lower case filenames in the current directory, it's no go. This is what is happening to you. Add three more lines to your script:
pwd >>/tmp/test.txt
echo [a-z] [A-Z] >> /tmp/test.txt
echo "[a-z]" "[A-Z]" >> /tmp/test.txt
and everything should become clear.

After you understand what was happening with your approach, try this:

typeset -u APPLICATION_UPPER
APPLICATION=hr_app
APPLICATION_UPPER=$APPLICATION
echo $APPLICATION_UPPER

ksh can upshift letters all by itself. No need for tr.
# 5  
Old 01-06-2003
Perderabo,

I added those lines and it became clear to me.

I looked in the home dir for this user, and someone had created a file named: i

I understand the problem, I just dont' understand why the echo command isn't being piped to the tr command. Why is tr looking in the home directory when it is being invoked from a | command?

Thank you very much for your help. I will use the typeset command. This was many hours of frustration.
# 6  
Old 01-06-2003
tr doesn't look in the home directory, but ksh will look in the current directory. When it did, it saw that file named i. So it replaced [a-z] with i and then it ran:
echo hr_app | tr i [A-Z]
# 7  
Old 01-06-2003
Lightbulb Got it

Ok, so without the "[a-z]", tr was looking at the filesystem. I added the "[a-z]" and it worked fine. Then I changed everything to typeset -u.

Thanks again for the help. After looking at the man page for tr, the examples always use the "".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. Shell Programming and Scripting

Who -u gives different output if run from cron than if run from terminal?

If I run 'who -u' interactively or from a script invoked through bash in a tty on my Ubuntu 12LTS box I get an output like this: testuser pts/0 Dec 9 02:32 . 2163 (host.xx.yy) running the same through cron I get: testuser pts/0 2012-12-09 02:32 00:05 2163... (2 Replies)
Discussion started by: latimer
2 Replies

3. Shell Programming and Scripting

Need help to run a script on cron

I need someone to help me out to upload script on host but I have problem can anyone help me out ? (2 Replies)
Discussion started by: spit
2 Replies

4. Shell Programming and Scripting

Run cron on every second Saturday ??

Hi, Can anyone help in editing CRON (OR) write a script to run another script every second saturday?? I tried to make use of DATE command to find the day but couldnt proceed further. your help is highly appreciated! Thanks, Mahi (11 Replies)
Discussion started by: mahi_mayu069
11 Replies

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

6. UNIX for Dummies Questions & Answers

cron does not appear to run

Hi everyone, I am having a problem with a cron, I am using Solaris 10 and need to run a php file every 5 minutes. I can run the file from the test user, but the cron does not seem to run. I do not see anything about it in /var/cron/log but see crons for other users running. What should I look... (10 Replies)
Discussion started by: atomicbits
10 Replies

7. Shell Programming and Scripting

Help with script - run by cron

Hello, I have a shell script that runs every minute to process incoming files delivered externally via SFTP to a directory. Basically the script works and processes the files however I get an error when a new file is delivered into the directory. Please see my script below. A new file is... (2 Replies)
Discussion started by: richo king
2 Replies

8. Linux

cron jobs not run

hi, I am newbie, I had set cron jobs to update something on one time very day, I had tested the script, it run fine, but the cron jobs seem never run. some help? Thanks. (4 Replies)
Discussion started by: robertsnoog
4 Replies

9. UNIX for Dummies Questions & Answers

Where does cron run from?

I have a script in the same directory as some files and directories im trying to tar up and I have it run in cron. Well it runs but says it can't find the directories, you need to be in the directory where the script is for it to work. Here is my cron and script its crappy but it does the trick =).... (3 Replies)
Discussion started by: kingdbag
3 Replies

10. UNIX for Advanced & Expert Users

cron fail to run

Hi, Does anyone know why the cron job fail to run automatically ? We have the problem with some Solaris 2.5.1 Machine ! The cron seemd to fail to submit the jobs defined at the defined time !! Why ? Sometime it runs OK,but sometime it fail . We are very sure the problem is due to... (6 Replies)
Discussion started by: kerwin_hsu
6 Replies
Login or Register to Ask a Question