- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: works on command line but does not work in cro...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 12:25 AM
10-10-2006 12:25 AM
I made one script which code I will post...script works fine from CL but in cron it has problems with second nawk. Script:
nawk -F"|" '
{ s=substr($104,2,18)}
{b[s] ++s}
END { for (i in b) print i, b[i] } ' $1 > /path/to/file/TranId_www$2
q=$(cat /path/to/file/TranId_www$2 | wc -l)
echo $q > /path/to/file/zawww
nawk -F"|" -v x=$2 -v w=$(/usr/bin/cat /path/to/file/zawww) '
{u=u+1; l=l+$66}
($66 != 0)&&($110 == 1)&&($111 == 0) { a=a+1; s=s+$66}
END { print x"|"u"|"l"|"w"|"s } ' $1 >> statistic_www
Also note that I got TranId_www$2 after script exec. in cron but statistic_www can not be appended..what might be an issue?
Pleaseeeee can anyone figure out what is problem and why does second nawk make problems??
THANKS in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 12:29 AM
10-10-2006 12:29 AM
Re: works on command line but does not work in cron
Unless you have established your own PATH in your script, 'cron' has only provided a minimal one, notably:
PATH=/usr/bin:/usr/sbin:.
Make sure that you have what you think you do!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 12:34 AM
10-10-2006 12:34 AM
Re: works on command line but does not work in cron
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 12:54 AM
10-10-2006 12:54 AM
Re: works on command line but does not work in cron
cat and echo may be missing their paths.
do you have a correct:
/path/to/file/zawww
file ?
You could run the script in debug mode (include "set -x" as the start of the script)
to track the path of code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 12:55 AM
10-10-2006 12:55 AM
Re: works on command line but does not work in cron
Cron runs with only a limited shell - be sure to fully the path to all commands.
In fact you may need to explicitly set some more environment variables that are not set by cron limited shell.
This is sometimes bypassed by using
su -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 01:11 AM
10-10-2006 01:11 AM
Re: works on command line but does not work in cron
it is not problem with path becouse I have my other script similar almost like this one:
nawk -F"|" -v x=$2 '
{u=u+1; l=l+$66}
($66 != 0)&&($110 == 1)&&($111 == 0) { a=a+1; s=s+$66}
#$66 != 0 { a=a+1; s=s+$66}
END { print x"|"u"|"l"|"a"|"s } ' $1 >> statistic_www
and this works from my cron..so as U can see it can recognise nawk and other things..but in script from my first post first nawk is executed brcouse I can see TranId_www$2 but second is not becouse file does not append..
any better ideas?? thanks for reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 04:33 AM
10-10-2006 04:33 AM
Re: works on command line but does not work in cron
#!/usr/bin/sh
export PATH=/usr/bin
However, in your code, you have not specified a location for the file "statistic_www". It will need a fullpath to ensure it goes where you want it. cron runs your script on your behalf but never performs a login so none of your /etc/profile and .profile will be run. And to further troubleshoot the problem, add the command set -x at the beginning of the script.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 07:15 AM
10-10-2006 07:15 AM
Re: works on command line but does not work in cron
have you looked for statistic_www
in the cron user's home directory?
Does the mail to the cron user give any clue?
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 04:02 PM
10-10-2006 04:02 PM
Re: works on command line but does not work in cron
I guess you have not defined which shell you are using, try defining in the first line of the script.
regards
hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 05:59 PM
10-10-2006 05:59 PM
Re: works on command line but does not work in cron
as U can see it is almost the same script no export PATH, no specificatio on shell, no path to statistic_www...and this script works just fine in cron! but script that I published in first post can not be completely executed in cron..
any clue??
thanks I hope that someone will give me a good hint which I have not tried yet.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 06:09 PM
10-10-2006 06:09 PM
Re: works on command line but does not work in cron
what i mean to say is,an example:
if you are using sh then define it as #!/bin/sh
rgds,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 06:59 PM
10-10-2006 06:59 PM
Re: works on command line but does not work in cron
1. Can you check your /var/adm/cron/log and see if you have error there?
2. Can you add "set -x" in your cronjob either at the top or before the second nawk ... and check /var/adm/cron/log after cronjon run
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2006 07:16 PM
10-10-2006 07:16 PM
Re: works on command line but does not work in cron
did you get the zawww file? I think like others that this is a problem of the PATH variable. So if you dont get the zawww file, then try to use full path for cat and echo commands or set the PATH in your script to suite your needs.
Hope this helps
Regards Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2006 12:14 AM
10-11-2006 12:14 AM
Re: works on command line but does not work in cron
1. add this to the top of you little program.
"/usr/bin/env > /tmp/my_env.txt"
2. run it by hand.
3. mv /tmp/my_env.txt /tmp/my_env.byhand.
4. run it by cron.
5. mv /tmp/my_env.txt /tmp/my_env.bycron.
6. cd /tmp
7. diff /tmp/my_env.byhand /tmp/my_env.bycron
8. look at the differences in the environment between running the job by hand and running the job by cron.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2006 11:20 PM
10-11-2006 11:20 PM
Re: works on command line but does not work in cron
I will reply soon..I hope that is an issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2006 01:14 AM
10-13-2006 01:14 AM
Re: works on command line but does not work in cron
HOME=/
LOGNAME=root
PATH=/usr/sbin:/usr/bin
SHELL=/usr/bin/sh
TZ=MET
# cat my_env.manual
PMTAG=inetd
PWD=/export/home/roberto
ISTATE=enabled
TZ=MET
LC_MESSAGES=C
HZ=100
HOSTNAME=x5sel6
LD_LIBRARY_PATH=/usr/dt/lib:/usr/openwin/lib:/opt/SMAW/lib:/opt/Navisphere/lib
OMNI_HOME=/export/home/omni
PERL5LIB=:/opt/SMAW/SMAWsuf
NLSPATH=:/export/home/omni/locale/%L/%N.cat:/export/home/omni/locale/%L/%N
CLASSPATH=/export/home/omni/classes/Signalware.jar:
MANPATH=/usr/share/man:/opt/SMAW/man:/usr/dt/man:/usr/openwin/man:/usr/share/man:/export/home/omni/man:/usr/local/man:/opt/nsr/man:/opt/Navisphere/man
ENV=/.kshrc
_DVFS_RECONFIG=YES
LC_TIME=en_US.ISO8859-1
MACHTYPE=sparc-sun-solaris
XFILESEARCHPATH=/usr/dt/%T/%N%S:/usr/openwin/lib/%T/%N%S:
MAIL=/var/mail/root
EDITOR=vi
LANG=C
LC_NUMERIC=en_US.ISO8859-1
LOGNAME=root
SHLVL=2
LC_CTYPE=en_US.ISO8859-1
_=/usr/bin/env
SHELL=/bin/bash
HOSTTYPE=sparc
OSTYPE=solaris
HOME=/
TERM=vt100
PATH=/usr/local/sbin:/usr/local/bin:/export/home/omni/java/bin:/export/home/omni/bin:/usr/dt/bin:/usr/openwin/bin:/usr/sbin:/usr/bin:/opt/SMAW/bin:/opt/SMAW/sbin:/opt/nsr:/opt/FJSVhwr/sbin:/opt/SMAW/SMAWsuf/bin:/opt/Navisphere/bin
LC_MONETARY=en_US.ISO8859-1
SHM=0
LC_COLLATE=en_US.ISO8859-1
so U were right it is not a same..but what should I do now in my case..
please looking forward of hearing from U
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2006 01:21 AM
10-13-2006 01:21 AM
Re: works on command line but does not work in cron
as mentioned somewhere above do a export PATH=.... at the beginning of your script.
The PATH variable should contain all necessary paths to the commands and tools you use in your script (typically /usr/bin:/usr/sbin).
That should do the trick.
Kind Regards
Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2006 01:29 AM
10-13-2006 01:29 AM
Re: works on command line but does not work in cron
if I put export PATH=...at the beginning of my script does it mean that path variables will be changed only during script execution in cron or forever???
If forever is the case than, I could create some other possible troubles..
what do U think?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2006 01:31 AM
10-13-2006 01:31 AM
SolutionI took your local env data and removed anything that looked specific to your login. I.e TERM, LOGIN, PWD....
You have two choices for this text.
1. Put text in your program you are running. Put the text just below the #!/bin/??? that is on the top line.
2a. Make a file like mycron.env and put this stuff in in.
2b. Put the following line in your program you are running. Put it just below the #!/bin/??? that is on the top line.
the line:
. /xxxx-the-full-path-xxxxx/mycron.env
Then try running the stuff. Besides the PATH needing to go in, I also see PERL5LIB is set, as well as a pile of other stuff.
Here is your mycron.env.
Steve
the text:
PMTAG=inetd
ISTATE=enabled
TZ=MET
LC_MESSAGES=C
HZ=100
HOSTNAME=x5sel6
LD_LIBRARY_PATH=/usr/dt/lib:/usr/openwin/lib:/opt/SMAW/lib:/opt/Navisphere/lib
OMNI_HOME=/export/home/omni
PERL5LIB=:/opt/SMAW/SMAWsuf
NLSPATH=:/export/home/omni/locale/%L/%N.cat:/export/home/omni/locale/%L/%N
CLASSPATH=/export/home/omni/classes/Signalware.jar:
MANPATH=/usr/share/man:/opt/SMAW/man:/usr/dt/man:/usr/openwin/man:/usr/share
/man:/export/home/omni/man:/usr/local/man:/opt/nsr/man:/opt/Navisphere/man
ENV=/.kshrc
_DVFS_RECONFIG=YES
LC_TIME=en_US.ISO8859-1
MACHTYPE=sparc-sun-solaris
XFILESEARCHPATH=/usr/dt/%T/%N%S:/usr/openwin/lib/%T/%N%S:
LANG=C
LC_NUMERIC=en_US.ISO8859-1
LC_CTYPE=en_US.ISO8859-1
SHELL=/bin/bash
HOSTTYPE=sparc
OSTYPE=solaris
PATH=/usr/local/sbin:/usr/local/bin:/export/home/omni/java/bin:/export/home/omni/bin:
/usr/dt/bin:/usr/openwin/bin:/usr/sbin:/usr/bin:/opt/SMAW/bin:/opt/SMAW/sbin:/opt/nsr:/o
pt/FJSVhwr/sbin:/opt/SMAW/SMAWsuf/bin:/opt/Navisphere/bin
LC_MONETARY=en_US.ISO8859-1
SHM=0
LC_COLLATE=en_US.ISO8859-1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2006 01:34 AM
10-13-2006 01:34 AM
Re: works on command line but does not work in cron
Once the job is done, the variables are cleared. You already painfully know this. Most of your variables are NOT loaded when you run your script as a cronjob.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2006 01:34 AM
10-13-2006 01:34 AM
Re: works on command line but does not work in cron
as this cron job runs in a seperate shell the export PATH is only valid for this shell as long as your script is running. With the end of your script the shell and with it the export PATH dies.
No other process on your system will recognize the different setting on the path variable.
Hope this helps
Regards Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2006 01:58 AM
10-13-2006 01:58 AM
Re: works on command line but does not work in cron
Or I missunderstood you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2006 02:27 AM
10-13-2006 02:27 AM
Re: works on command line but does not work in cron
Oh well. Run "man export". You'll see that "export PATH" means the PATH will stay as you proceed further INTO the shell.
Uh...that sounds a little goofy.
You have 3 files: f1.sh, f2.sh and f3.sh
contents f1.sh
MYVAR="this is a test"
MYVAR2="this is a test2"
export MYVAR2
echo "in f1 MYVAR is $MYVAR MYVAR2 is $MYVAR2"
sh ./f2.sh
contents of f2.sh
echo "in f2 MYVAR is $MYVAR MYVAR2 is $MYVAR2"
sh ./f3.sh
contents of f3.sh
echo "in f3 MYVAR is $MYVAR MYVAR2 is $MYVAR2"
Now go ahead make the 3 files and run them.
Now pretend that MYVAR is really PATH. You should get your own answer this way.
Go ahead and change MYVAR and/or MYVAR2 to PATH and see what happens. You'll see that nothing nasty happens at all.
steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2006 06:00 PM
10-15-2006 06:00 PM
Re: works on command line but does not work in cron
Thanks, :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2006 07:51 PM
10-16-2006 07:51 PM
Re: works on command line but does not work in cron
hope your problem will be solved with adding the PATH variable.
@Steve: Thanks for waiting and also thanks for taking over. I was away from keybord at that time and couldn't answer.
Kind regards
Stefan
BTW: how about assigning points to the other replies? Everybody posting here tried to help you, and you might want to say "thank you" by assigning points. (Please no points for this reply).