- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Run crontab job
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
05-16-2007 01:23 PM
05-16-2007 01:23 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 01:30 PM
05-16-2007 01:30 PM
Solution- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 01:44 PM
05-16-2007 01:44 PM
Re: Run crontab job
This kind of problem is usually the otherway around. As in within the Shell you can run the script fine, but fails in Cron.
Since its failing in the shell, execute 'set -x' (assuming you're run Bourne/Korn) then run the script. This should show you when the problem is or the last command that failed.
Jov
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 01:52 PM
05-16-2007 01:52 PM
Re: Run crontab job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 02:02 PM
05-16-2007 02:02 PM
Re: Run crontab job
I hv two more questions
1. as A.Clay said , how can I "export any needed environment" ? how can I know all my environment ?
2. As A.Clay said , when login with the batch user , it will run the .profile and global profile ( I have set it for my application ) . Is it possible when I run it on shell , the enviornment change to the same as run it by crontab ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 02:11 PM
05-16-2007 02:11 PM
Re: Run crontab job
It's a little difficult to understand your problem.
Answer this very precisely. If you run your script from the shell (NOT FROM CRON), does the script execute properly? Yes or No?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 02:25 PM
05-16-2007 02:25 PM
Re: Run crontab job
thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 02:59 PM
05-16-2007 02:59 PM
Re: Run crontab job
Add set -x near the top of your script and try to run it. You should see exactly what is wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 03:14 PM
05-16-2007 03:14 PM
Re: Run crontab job
I tried to run "set -x" on shell , but no any output , what is the function of this command ?
ps. I use bash.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 03:45 PM
05-16-2007 03:45 PM
Re: Run crontab job
In a real shell, set -x will list to seterr the commands as it executes them. See ksh(1) or sh(1).
>I use bash.
Change your shell to sh or ksh? At least until you get it working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 03:59 PM
05-16-2007 03:59 PM
Re: Run crontab job
Here's one reason:
echo "One Two Three" | read A B C
echo "A = ${A} B = ${B} C = ${C}"
That works on the POSIX shell and most Korn shell implementations; it fails on most bash implementations. We can argue about the proper handling of lvalues and subprocess but the above construct is very useful.
Now, is this an HP-UX question or a Linux question?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 04:04 PM
05-16-2007 04:04 PM
Re: Run crontab job
I have a bit confuse ,
do you mean I should change it to ksh to test it , add "set -x" to my script and try to run it on shell to see any error message ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 04:13 PM
05-16-2007 04:13 PM
Re: Run crontab job
Secondly, I don't care what shell YOU use; that's your choice but you should at least know how to enable debugging mode for whatever shell you do use. All I am saying is that contrary to world opinion bash may not be the world's best shell. For example, on Linux, I use the zsh when possible. Moreover, it is very possible that the problem you are describing is a direct consequence of running under different shells when under cron and when in an interactive environment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 04:16 PM
05-16-2007 04:16 PM
Re: Run crontab job
Well, as Clay says, you shouldn't use bash at all. ;-)
First you need to look at your bash documentation and see if it supports a set -x like option will enable tracing of script executation.
From my 3.0 bash man page, set -x does do what a real shell says it should. So this means if you don't get any output, we have to address this.
(You can test this by adding "set -x" to a simple bash script and then see of the rest of the commands in the script get echoed.)
For a real shell, you can also add the -x on the first line:
#!/usr/bin/sh -x
Or:
#!/usr/bin/bash -x
(Whatever your bash path is.)
Try that for your bash script.
First try adding -x, then try changing the shell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 04:47 PM
05-16-2007 04:47 PM
Re: Run crontab job
one dirty way to do this is to create a crontab entry that runs the job as if you ran it manually.
this should look something like this:
#*******************************************************************************
12 18 * * * echo "/path/scripts/myscript.sh; exit"|su - yogeeraj 1>/home/yogeeraj/logfiles/output.crn 2>/home/yogeeraj/logfiles/error.crn
#*******************************************************************************
# END OF TABLE day0->Sunday day6->Saturday
#*******************************************************************************
hope this helps!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 08:35 PM
05-16-2007 08:35 PM
Re: Run crontab job
I am checking how to use "set -x" , I think the function of this command is to debug error. Except this method , is there other simply way to make the environment ( run by manually ) to the same as run by crontab ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2007 09:05 PM
05-16-2007 09:05 PM
Re: Run crontab job
Nobody would EVER want to do that except to debug a bad crontab entry. This was mentioned by Clay and Jov.
To do this, you would have to remove ENV vars and limit the PATH to what crontab(1) says.
And as Clay mentioned, if you have functions that work only on tty devices, you need to exclude those.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2007 03:22 PM
05-17-2007 03:22 PM
Re: Run crontab job
The below is user's env after login.
MANPATH=/usr/share/man:/usr/local/man
src=/ora_usr/src
HOSTNAME=ora
Now , if I want all schedule job ( crontab ) also has this env , what can I do ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2007 03:49 PM
05-17-2007 03:49 PM
Re: Run crontab job
But why you need to do this? Removing things tend to break crontabs not fix them.
Jov
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2007 05:11 PM
05-17-2007 05:11 PM
Re: Run crontab job
Add them to the start of the script. If its a command then you'll need to wrapper it within a script -- > can advise how can I wrapper it within a script ?
But why you need to do this? Removing things tend to break crontabs not fix them.
--> I guess it is the simplest way to fix it , I know it will "break crontabs" , do you think it is harmful to the system ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2007 05:59 PM
05-17-2007 05:59 PM
Re: Run crontab job
As my previous question , now the crontab can run normally by manual but can't run by crontab , so is it possible to do that - when run a script by crontab , it is exactly the same env as run by manual ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2007 07:27 PM
05-17-2007 07:27 PM
Re: Run crontab job
what I want is just to change the env of a crontab job , I tried to add the below script to a crontab job but still fail , can advise what is wrong ? thx
where env_cron is user's env.
for i in $(cat /tmp/env_cron)
do
export ${i}
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2007 07:36 PM
05-17-2007 07:36 PM
Re: Run crontab job
pls, can you post your script and the output you get running it manually?
This may help to go to rifght direction.
Rgds,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2007 08:13 PM
05-17-2007 08:13 PM
Re: Run crontab job
"so is it possible to do that - when run a script by crontab , it is exactly the same env as run by manual ? "
as mentioned previously, you should try the easy method of just doing:
echo ".<script>.."| su - user
where
hope this helps too!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2007 09:03 PM
05-17-2007 09:03 PM
Re: Run crontab job
I also want to post the output , but this involve my application , the script is very long , but as the previous reples , this problem is very common as they have different env ( i still think this is the reason ) , so I would like to fix this problem by simply changing the env as my previous question .
thx a lot.