- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Diff between running something tru CRON and prompt
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
Discussions
Discussions
Discussions
Forums
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
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
тАО12-04-2002 07:33 AM
тАО12-04-2002 07:33 AM
test: argument expected
when I run the script from cron, and it runs fine if run from a command prompt.
What should I look for ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 07:36 AM
тАО12-04-2002 07:36 AM
Re: Diff between running something tru CRON and prompt
run env at the top of the script.
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 07:38 AM
тАО12-04-2002 07:38 AM
Re: Diff between running something tru CRON and prompt
Normal logins will have the details from /etc/PATH, /etc/profile and a number of other config files set, which cron will not.
In order to run things in cron as you would at the command line, you need to make sure that any relevant variables are set at the start of the cron job
eg:
PATH=`cat /etc/PATH`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 07:41 AM
тАО12-04-2002 07:41 AM
Re: Diff between running something tru CRON and prompt
First of all, the test or if [ operand should be enclosed in "" so that the behavior is better defined for null arguments. You fundamental problem is almost certainly an undefined environment variable. Note: cron or at does not source a user's .profile (and generally it should not do this explicitly because .profile's often have commands which expect a terminal connection. The correct way to deal with this is to have a file like /usr/local/bin/myenv.sh which sets and exports any needed varaiables and then this file should be sourced (using . /usr/local/bin/myenv.sh) by both the user's .profile and your cron'ed script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 08:33 AM
тАО12-04-2002 08:33 AM
Re: Diff between running something tru CRON and prompt
I normally run cron jobs with full pathnames and whatever variables set that it is expecting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 09:19 AM
тАО12-04-2002 09:19 AM
Re: Diff between running something tru CRON and prompt
(The error line has *** below, and this is my first line in the script:
#!/usr/bin/ksh)
if ( [[ $todays_day = "Sat" ]] && (( $todays_time > 6 )) ) || ( [[ $todays_day = "Sun" ]] ) || ( [[ $todays_day = "Mon" ]] && (( $todays_time < 8 )) )
then
if ( [[ $todays_day = "Sat" ]] && (( $todays_time > 7 )) ) && ( [[ $todays_day = "Sat" ]] && (( $todays_time < 12 )) )
then
***if [ $ora_err_num = ORA-12012: ]
then
weekend=n
fi;
fi;
else
weekend=y
fi;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 09:22 AM
тАО12-04-2002 09:22 AM
Re: Diff between running something tru CRON and prompt
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 09:29 AM
тАО12-04-2002 09:29 AM
Solutionif [ $ora_err_num = ORA-12012: ]
should be
if [ "${ora_err_num}" = "ORA-12012:" ]
I assume that all that date stuff is being set by the 'date' command; make sure that it is in your PATH.
The fundamental problem here is that $ora_err_num is almost certainly not being set.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 09:29 AM
тАО12-04-2002 09:29 AM
Re: Diff between running something tru CRON and prompt
ora_err_num=`echo $x1`
Please keep in mind that this scritps runs great from a prompt !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 09:31 AM
тАО12-04-2002 09:31 AM
Re: Diff between running something tru CRON and prompt
It appears that 'ora_err_num' is null. If you use quote marks ("") to surround the variable, then your then the test occur even if the variable is null. Quoting variables in test statements is strongly urged:
if [ "$ora_err_num" = ORA-12012: ]
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 09:32 AM
тАО12-04-2002 09:32 AM
Re: Diff between running something tru CRON and prompt
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 10:15 AM
тАО12-04-2002 10:15 AM
Re: Diff between running something tru CRON and prompt
without further checking your script:
ALWAYS quote all substitutions in scripts!
"test" is just to prone to bark on those *empty* substitutions...
FWIW,
Wodisch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 10:50 AM
тАО12-04-2002 10:50 AM
Re: Diff between running something tru CRON and prompt
The problem was the variable not being set, because there were no error in the log that I was scanning. And the reason it was working from the prompt (vs. CRON) was becuase I was referencing a file in the local dir (which did not have the full path defined).
In conclusion, which is the better way /more accurate way to avoid the variable having a null value:
if [ "${ora_err_num}" = "ORA-12012:" ]
--OR--
if [ "$ora_err_num" = ORA-12012: ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 10:53 AM
тАО12-04-2002 10:53 AM
Re: Diff between running something tru CRON and prompt
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 11:02 AM
тАО12-04-2002 11:02 AM
Re: Diff between running something tru CRON and prompt
You should simply get in the habit of enclosing every shell variable in {}'s.
Enclosing possible null test operands in quotes ensures that you will not generate a shell syntax error and terminate the shell but there may still be a problem with the data itself. You could detect that error with
if [[ -n "${var} ]] and deal with it inside your script.