- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- cron wont run ..
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
07-17-2001 10:37 AM
07-17-2001 10:37 AM
I have put the space with crontab -e
/path/ ./script
I made sure it was the right shell at top #!/usr/bin/sh .. On the cron log I see rc=1.
Any ideas?
Thanks
Richard
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2001 10:48 AM
07-17-2001 10:48 AM
Re: cron wont run ..
The most usual problem with scripts that execute from a command line but not from a crontab is the absence of proper environmental variable and/or PATH.
Unless you provide any variables, particularly including your PATH as you would have when your $HOME/.profile is sourced at login, it is common for a script to fail.
You can source (read) your profile ahead of calling your script. This can/should be done in the crontab entry. Alternatively, you could source your profile within the script itself to provide the necessary environmental variables you need. Thirdly, you could create a new file which contains and exports the common variables needed for your application, and source (read) that within your standard profile, within standard scripts; and/or in a crontab stream.
To source (read) a file within a script, put a dot (".") in front of the script name. For instance, to source a file called /myscript you would do:
. /myscript #...note the space between the dot and the script name.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2001 10:51 AM
07-17-2001 10:51 AM
Re: cron wont run ..
Are you running the cron job as root? if so, did it send you a mail when it ran? There might be some information about why it failed. Also, are there any environment vairables that are used in the script? it seems to me that there have been problems passing those variables to a cron job and you have to do some special coding to get them in.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2001 10:51 AM
07-17-2001 10:51 AM
Re: cron wont run ..
This almost always is a result of the fact that cron runs in a very sparse environment.
Let's say that you are running a cronjob as user oracle, you expect that things like ORACLE_SID, TNS_ADMIN, etc. are set because they are in oracle's .profile. Wrong because .profile is not sourced and thus not only are these environment variables not set but even the PATH is very limited.
The best way to do this is to create a file like /usr/local/bin/oraenv.sh and let it set
and export any needed environment variables. Do not put an exit statement in this file. You the add . /usr/local/bin/oraenv.sh in oracle's .profile and also let it be sourced by your cron script. You can also simply do all the exports explicitly in your cron script but the first method is better because you need only make changes in one place.
I've obviously used oracle as an example but you get the idea.
REgards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2001 10:55 AM
07-17-2001 10:55 AM
Re: cron wont run ..
As other says it could be variable problem or path problem. use full path inside the script for any command. for example.
set remove= "/usr/bin/rm"
If you can paste your script here.
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2001 11:02 AM
07-17-2001 11:02 AM
Re: cron wont run ..
I do have a few variables in here.
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2001 11:04 AM
07-17-2001 11:04 AM
Re: cron wont run ..
If you see someone that I did wrong or know a better way to do it. please tell me, dont hold back. Im here to learn from the masters.
Richard =)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2001 12:09 PM
07-17-2001 12:09 PM
SolutionI see several possible problems but they all relate to what's been said.
1) Your hostname file is a relative path. You need to either cd to some desired location or
specify an absolute path.
2) For EVERY command that is not a shell built-it, the golden rule in cron is specify the absolute path or better set and export PATH within your script. For example, do a type ping, a type bdf, etc.
/usr/sbin/ping
/usr/bin/bdf
At the very least, you should then
PATH=/usr/sbin/ping:/usr/bin/:${PATH}
export PATH
This may not be all be you get the idea, remember the cron environment is intentionally very sparse and stupid; you have to tell it everything. It can barely spell cron on its own.
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2001 02:43 PM
07-17-2001 02:43 PM
Re: cron wont run ..
I didnt realize that cron was "dumb"
If anyone is still reading this post are there any books or websites that I can go to for more info on profiles and shells? ..
Thanks for your help.
Ps: Mr "King" James .. I didnt mean to give you a 6 .. I was trying to give you a 7.
Richard =)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2001 03:35 PM
07-17-2001 03:35 PM
Re: cron wont run ..
Your script now looks much better but one minor criticism. You execute /usr/sbin/ping
but you have already added /usr/sbin/ to your PATH. You can now simply execute ping. I would say use the absolute pathname or set PATH. You're not wrong this is just better form.
As for online docs, I have not been able to find any decent tutorials. You can and should
man sh-posix | lp to get a printed copy. This is very detailed and quite good but short on examples.
My favorite shell programming book is 'Unix Shell Programming' by Stephen G. Kochan & Patrick H. Wood. The O'reilly 'Learning the Korn Shell' is pretty good also. Both of these are available from amazon.com. Don't worry about differences between POSIX shell and Korn shell at this point. The differences are minor.
The other thing to do is convince your boss to start a UNIX library. This is a must. The very best place to start is:
http://www.oreilly.com
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2001 06:06 PM
07-17-2001 06:06 PM
Re: cron wont run ..
You asked about "favorite" books on Shell programming.
I particularly like "UNIX Shell Programming" by Lowell Jay Arthur & Ted Burns, 3rd ed. copyright 1994, John Wiley & Sons, IBSN 0-471-59941-7.
...and for a quick reference and a good overview of the major shells, I would add HP's own "Shells: User's Guide":
http://docs.hp.com/hpux/onlinedocs/B2355-90046/B2355-90046.html
Lastly, don't forget the 'sh-poxix' man pages. There is a wealth of good information there.
The question of "favorites" has come up before. Here's another link with come additonal comments:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0xbb5e7e990647d4118fee0090279cd0f9,00.html
I would concentrate on the Posix shell (or ksh, from which it derives). The default shell for root *must* be the Posix shell as must all scripts in the /sbin/rc?.d/ startup directories. I'd avoid the c-shell (csh). It's hardly used, and lacks sophisticated features. Learn Poxix and you can naturally use the ksh and bash shells too.
Finally, read and study existing scripts whenever you can. There's plenty of good tricks and techniques to be learned. Write as often as you can.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 10:15 AM
07-18-2001 10:15 AM
Re: cron wont run ..
try /sbin/init.d/cron stop
and /sbin/init.d/cron start
Nora