LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-22-2009, 01:10 PM   #1
Dcrusoe
Member
 
Registered: Oct 2004
Location: San Diego
Distribution: Mandrake Linux 10.1
Posts: 30

Rep: Reputation: 15
script using "/usr/bin/cat error" produces "cannot open" in cron


Okay, once again I come hat in hand with a dumb issue. I have a script that work from the command line, but error on a cat of a tmp file when run from cron.

script is running #!/bin/ksh

I am using three tmp files which I have set up in the script to rm -rf them before the main script runs
And then just doing a simple
sed 's/^.//g' $TMP2 > $TMP3

this creates the tmp3 file just fine. the file no will contain numbers without the leading zeros like so:
2486
1009
6750
1126
8836
1125
8649
1060
1057
9849
7082
8847

Then after some header crap echoes out to the report I do a

for i in `/usr/bin/cat tmp.3`
do
z=`grep $i /usr/projects/sds/1,5/usr.log`
echo "$i ->\r\n $z" >>$HDRPT
done

This works when I run it using sh -x and runs normally with a ./filename, and with full path to the script at the command line.

However in cron it does not run correctly and the error is regarding the cat command.

cat: 0652-050 Cannot open tmp.3.
cat: 0652-050 Cannot open tmp.3

Two errors as I have the command running twice in the script with two different greps. The headers go to the finale report fine and the tmp files are all correctly updated. So I seem to be over looking an issue with how the cat command can be run on cron. I have as you can see full path but I am also making a call to the user profile as my first command.

Suggestions or is this to little information?

Thanks in advance for any thoughts.
 
Old 07-22-2009, 02:28 PM   #2
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
It is difficult to give an exact solution because we don't have the whole script, but I can make a fair guess that the problem lies in the fact that cron doesn't have a tty or a full user environment. I know you are sourcing a user's profile, but that may not be enough. There are other possibilities; missing path specifications, permission mismatches, some others but more detail would help...
 
Old 07-22-2009, 03:06 PM   #3
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

check the working directory, when the script runs from cron. May be, there's no write permission in that directory, so the file can't be created. You should use absolute pathnames for your temporary files to make sure, that you create them in a writable path.

Jan
 
Old 07-22-2009, 03:21 PM   #4
Dcrusoe
Member
 
Registered: Oct 2004
Location: San Diego
Distribution: Mandrake Linux 10.1
Posts: 30

Original Poster
Rep: Reputation: 15
issue details with script

okay whole script below. Note that I have a file showing users logging into a menu and what they do in the menu, I first pull just the help desk guys from it (tmp.1), then I pull just a user id number(tmp.2), they all have a leading zero in it that I then have to get rid of (tmp.3), finally I use tmp.3 to grep out the id number from yet another file. Note also the headers that I show going to the file do go to the file when run in cron. The only thing not working is the cat command. Maybe it's the fact it is in ksh? I am home now but tomorrow I'll try it under sh, though i and my users all use the ksh shell. Anyway I've commented out the cat and replaced it with numbers embedded in the script and it of course runs. I still think it is something with the cat command, but hey what the hell do I know.


<=====================start script====================================>
#Call .profile to setup the environment so script can also be run from cron
. /usr/projects/sds/defs/.sds_profile

check_for_error()
{
#LOOK FOR AN ERROR MESSAGE FROM TRANS-BASIC -OR- A PROGRAM
egrep "\?Syntax error|UNEXPECTED PROGRAM ERROR" $LOGFILE > /dev/null
if [ "$?" = "0" ]
then
echo "\a\c" > /dev/console
date=`date +"%d-%h-%y %H:%M"`
echo "\r\n"$date" ** SDSII:HDUSER.COM Processing ABORTED" > $consol_log_printer
echo "\r\n"$date" ** Check SDSII:HDUSER.LOG for errors\r\n" > $consol_log_printer
exit 1
fi
}

# set and clear temp files
LOGFILE=/usr/projects/sds/1,3/hduser.log
HDRPT=/usr/projects/sds/1,5/hduser.rpt
TMP1=/usr/projects/sds/1,3/tmp.1
TMP2=/usr/projects/sds/1,3/tmp.2
TMP3=/usr/projects/sds/1,3/tmp.3
/bin/rm -rf $LOGFILE
/bin/rm -rf $TMP1
/bin/rm -rf $TMP2
/bin/rm -rf $TMP3

#SEND BATCH FILE STARTUP MESSSAGE TO THE CONSOL LOG PRINTER
date=`date +"%d-%h-%y %H:%M"`
echo "\r\n"$date" ** SDSII:HDUSER.COM Processing In Progress\r\n" > $consol_log_printer

# First is to get an updated list
# We do this by running the emps prgram and letting it print a employee report
# by Job Function

#fmemps
tbasic << !EOF! >> $LOGFILE
RUN SDSII:FMEMPS
4
R
J

!EOF!
check_for_error

# All Helpdesk are listed under "MIS Help Desk"
# so grep them out and throw them to a tmp file.

grep "MIS Help Desk" /usr/projects/sds/1,5/emps.rpt > $TMP1

# But we only need the gaming license number not
# everything else so use sed to grab that field.

awk '$1 {print $1}' $TMP1 > $TMP2

# But the report gives us the license with a leading zero so get rid of that.

sed 's/^.//g' $TMP2 > $TMP3

# Now we can finally produce the report, but is it today info or yesterday's
# info. Throw a header to the final report, first we do today's info, then
# we need to grep the usr.log file as that is todays stuff.

echo " TODAY'S HELPDESK USER LOG" > $HDRPT
echo "\r\n"$date"\r\n" >> $HDRPT
echo " DATE TIME REQUESTED OPTION ACCESS KB LOGICAL EMP ID EMPLOYEE NAME" >> $HDRPT
echo " ------- ----- -------------------------- ------------------ -- ------- ------ --------------------" >> $HDRPT
sleep 1

for i in `/usr/bin/cat tmp.3`
do
z=`grep $i /usr/projects/sds/1,5/usr.log`
echo "$i ->\r\n $z" >>$HDRPT
done

# Now we produce yesterdays info for the report.
# Throw another header to show is yesterday's info, then
# we need to grep the usr.rpt file as that is yesterdays stuff.

echo " YESTERDAY'S HELPDESK USER LOG" >> $HDRPT
echo " DATE TIME REQUESTED OPTION ACCESS KB LOGICAL EMP ID EMPLOYEE NAME" >> $HDRPT
echo " ------- ----- -------------------------- ------------------ -- ------- ------ --------------------" >> $HDRPT

for i in `/usr/bin/cat tmp.3`
do
z=`grep $i /usr/projects/sds/1,5/usr.rpt`
echo "$i ->\r\n$z" >>$HDRPT
done

#SEND BATCH FILE COMPLETED MESSSAGE TO THE CONSOL LOG PRINTER
date=`date +"%d-%h-%y %H:%M"`
echo $date" ** SDSII:HDUSER.COM Processing Completed\r\n" > $consol_log_printer
 
Old 07-22-2009, 03:26 PM   #5
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

using the "code" tags would be nice ;-) You should use the $TMP3 variable whithin the cat loop instead of "tmp.3", otherwise it works only if your working directory is /usr/projects/sds/1,3

Jan
 
Old 07-22-2009, 03:27 PM   #6
Dcrusoe
Member
 
Registered: Oct 2004
Location: San Diego
Distribution: Mandrake Linux 10.1
Posts: 30

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jan61 View Post
Moin,

using the "code" tags would be nice ;-) You should use the $TMP3 variable whithin the cat loop instead of "tmp.3", otherwise it works only if your working directory is /usr/projects/sds/1,3

Jan
oh crap! yes! bloody hell. I did say dumb right?
 
Old 07-22-2009, 03:30 PM   #7
Dcrusoe
Member
 
Registered: Oct 2004
Location: San Diego
Distribution: Mandrake Linux 10.1
Posts: 30

Original Poster
Rep: Reputation: 15
Thumbs up

Quote:
Originally Posted by jan61 View Post
Moin,

using the "code" tags would be nice ;-) You should use the $TMP3 variable whithin the cat loop instead of "tmp.3", otherwise it works only if your working directory is /usr/projects/sds/1,3

Jan
\ such a dumb miss! Thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 06:58 AM
LFS6.3 - Ch5.4.1 "/bin/sh sort not found" error at "make bootstrap" ubyt3m3 Linux From Scratch 2 06-23-2008 12:09 AM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 04:51 AM
what is "S" instead of "X" in the file permission when i look at /usr/bin/chsh? Linux_interest Linux - Newbie 4 08-28-2004 09:22 AM
Monthly Archiving Script... help with "date" & "cron" Supp0rtLinux Linux - Software 3 01-03-2003 09:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration