Job runs manually, doesn't work in crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Job runs manually, doesn't work in crontab
# 15  
Old 06-15-2016
Thanks for the explanation, Don.

I changed
Code:
shell=/bin/bash

in the script to

Code:
#!/bin/bash
HOME="/home/admin"
cd "$HOME"
[ -f .bash_profile ] && . .bash_profile
[ -f .bash_login ] && . .bash_login
[ -f .profile ] && . .profile

Still didn't work using cron.

Quote:
One would expect that one or more of those three files initializes PATH (although it appears that your script doesn't depend on any utilities that are not on the default PATH that you aren't referencing with absolute pathnames) and other shell variables to the values you'll need to run /opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_export , but we can't know that for sure since we have no idea what other commands you have run after you last logged in to your system before you successfully run /opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_export from your interactive shell.
I don't need to run any commands after logging in before manually running the job for it to work.

How can I tell what an executable job is doing? I know it would help solve this if I had that information, but I don't know how to check, since it isn't a text file.
# 16  
Old 06-15-2016
Quote:
Originally Posted by df08388
Thanks for the explanation, Don.

I changed
Code:
shell=/bin/bash

in the script to

Code:
#!/bin/bash
HOME="/home/admin"
cd "$HOME"
[ -f .bash_profile ] && . .bash_profile
[ -f .bash_login ] && . .bash_login
[ -f .profile ] && . .profile

Still didn't work using cron.



I don't need to run any commands after logging in before manually running the job for it to work.

How can I tell what an executable job is doing? I know it would help solve this if I had that information, but I don't know how to check, since it isn't a text file.
You don' t need to run any of those commands manually after logging in because logging in runs those commands automatically before you see your first shell prompt. But, when you run a job with cron you don't login and your script has to do whatever it takes to create an environment in which the processes started by your script running under cron have the environment they need to get their work done.

As Jim McNamara suggested, create the following script in a file named get_cron_env:
Code:
#!/bin/bash
HOME="/home/admin"
cd "$HOME"
[ -f .bash_profile ] && . .bash_profile
[ -f .bash_login ] && . .bash_login
[ -f .profile ] && . .profile
env > environ.cron

Make that file executable with:
Code:
chmod +x get_cron_env

Set a crontab entry to run that script (using an absolute pathname for the script; not just get_cron_env).
And then run the commands:
Code:
env > /home/admin/environ.interactive
diff /home/admin/environ.cron /home/admin/environ.interactive

and show us the output.

There will likely be some differences because interactive environments have more stuff going on than background jobs like those started by cron. But, maybe we'll get lucky and see something that you can easily fix.

I can't help you find the source for the executable you have installed as /opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_expor. If you (the royal you meaning some administrator inside your company) wrote software and didn't provide documentation on how to run it, track down who wrote it and get them to tell you exactly what you have to do to run it from cron.

If this is third party software you bought from someone else, read the documentation that came with it. If you bought code from someone and didn't get documentation that tells you how to run it; shame on you. Contact the vendor and ask for support.

If this is third party software you downloaded free from someone else, read the documentation that came with it. If you downloaded code without documentation and without source, and without support; you've got what you paid for and I wish you luck. If you downloaded free source, look at it and figure out what it is doing that keeps it from working under cron and fix it. Or send mail to the support site for that free software and ask for help.

And, of course, if you downloaded a bootlegged copy of someone's software from a black site, we have absolutely no sympathy for you and will not further assist you in trying to fix code you stole from its creators. (But, we assume that you would never do that.)
# 17  
Old 06-17-2016
Thx, Don!

Sorry, too busy today to get to this. I'll create the script tomorrow, run the
Code:
DIFF

command, and post it here.

I inherited this without a lot a documentation, and I've been learning on the job. The code is legitimate and comes from Check Point Software Technologies (hence CPsuite-R77). I don't have any doc on it, but I'll try to find out more about it tomorrow.

What prompted this is the network team here at work was running this executable manually every Monday morning. I'm trying to automate it so we don't have to do that.

---------- Post updated 06-17-16 at 09:35 AM ---------- Previous update was 06-16-16 at 06:01 PM ----------

Here is the output from the command

Code:
diff /home/admin/environ.cron /home/admin/environ.interactive

Code:
2a3,4
> HOSTNAME=admin-comm
> TERM=xterm
4c6,7
< MAILTO=
---
>HISTSIZE=1000
> SSH_CLIENT=114.18.7.232 60699 22
6c9
< OLDPWD=/home/admin
---
> SSH_TTY=/dev/pts/2
19c22,23
< PATH=/opt/CPinfo-10/bin:/usr/bin:/bin:/opt/CPshrd-R77/bin:/opt/CPshrd-R77/util:/opt/CPshrd-R77/web/Apache/2.2.0/bin:/opt/CPsuite-R77/fw1/bin:/opt/CPsuite-R77/fw1/oracle_oi/sdk:/opt/CPsuite-R77/fg1/bin:/opt/CPda/bin:/opt/CPportal-R77/webis/bin:/opt/CPportal-R77/portal/bin:/opt/CPrt-R77/bin:/opt/CPuepm-R77/bin:/opt/CPuepm-R77/engine/jre/bin:/opt/CPshrd-R77/database/postgresql/bin:/opt/CPSmartLog-R77/bin:/home/admin/bin
---
> MAIL=/var/spool/mail/admin
> PATH=/opt/CPinfo-10/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/CPshrd-R77/bin:/opt/CPshrd-R77/util:/opt/CPshrd-R77/web/Apache/2.2.0/bin:/opt/CPsuite-R77/fw1/bin:/opt/CPsuite-R77/fw1/oracle_oi/sdk:/opt/CPsuite-R77/fg1/bin:/opt/CPda/bin:/opt/CPportal-R77/webis/bin:/opt/CPportal-R77/portal/bin:/opt/CPrt-R77/bin:/opt/CPuepm-R77/bin:/opt/CPuepm-R77/engine/jre/bin:/opt/CPshrd-R77/database/postgresql/bin:/opt/CPSmartLog-R77/bin:/home/admin/bin
20a25
> INPUTRC=/etc/inputrc
27a33
> SHLVL=1
29d34
< SHLVL=2
33a39
>SSH_CONNECTION=114.18.7.232.60699 114.18.45.8.22
39c45
< _=/usr/bin/env
---
> _=/bin/env

# 18  
Old 06-23-2016
Hoping for a response on this.
# 19  
Old 06-24-2016
The input shows us that you are manually changing PATH significantly after you login before you successfully invoke your script manually (which I find surprising), but since the your script works manually when PATH is just set to /bin:/usr/bin that probably isn't your problem. Nonetheless, since the number and order of directories before /bin and /usr/bin in PATH and even the order of these two directories changed between your cron job environment and your manual invocation environment, I would suggest that you explicitly set PATH in your script just before you invoke the command that is failing.

Nothing else in the differences between the environment variable setting raise any red flags, but with seeing the source code for the command that is not working we are just guessing. You NEED to contact the manufacturers of that code and ask them what you need to do to run their code from a cron job.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script runs manually, but not from cron

Hi, I "borrowed" a script I found online, to start a SAP router application on a Solaris 11 (SPARC) server. The script runs fine when calling it manually, but when I schedule it to run from cron, it doesn't. I don't see any warning or failure messages anywhere, just nothing happens. ... (11 Replies)
Discussion started by: bredman
11 Replies

2. UNIX for Dummies Questions & Answers

Script runs manually but not from crontab in UNIX

Hi Guys, I am executing the script called Delet.sh manually it is successfully completing the task but it is failing to run vi cron tab, I tried to pass PATH & .profile before execution but no luck, Any suggestions? Script below #!/usr/bin/ksh #set -x # Purpose : Delete folders file from... (9 Replies)
Discussion started by: Anilsa77
9 Replies

3. Shell Programming and Scripting

Script runs good manually but failing via crontab

Hello Gurus, I have written small script which will start the given service if its stop .Its running fine when manually executed but its unable to run from crontab. #!/bin/bash SERVICENAME=rsyslog service $SERVICENAME status > /dev/null SYSLOGSTATUS=`echo $?` COUNT=0 THRESHOLD=3 if ... (4 Replies)
Discussion started by: kapil514
4 Replies

4. Shell Programming and Scripting

Part of the Shell script is not running via crontab, runs fine manually

Hello Team, As a part of my job we have made a script to automate a service to restart frequently. Script having two functions when executing it's should find the existing service and kill it, then start the same service . Verified the script it's working fine when executing... (18 Replies)
Discussion started by: gowthamakanthan
18 Replies

5. Shell Programming and Scripting

Script runs fine manually but not in crontab

Hello Guys, I have scratched my head alot on this but couldn't find clue what's wrong. Can you please help me with this? My problem is as following. 1) When I manually execute following script it runs successfully with below output. bash-3.00# more smssend #!/bin/bash echo -e "<Request... (16 Replies)
Discussion started by: umarsatti
16 Replies

6. Shell Programming and Scripting

cronjob not running but runs manually

hello, i recently switched to a new ec2 box and transferred the cronjobs from the old box. For some reason one of the scripts won't work but it runs manually from the command line. I've read from previous threads it might be an environment issue but I added a line with the path to the script... (2 Replies)
Discussion started by: lencholamas
2 Replies

7. Shell Programming and Scripting

Script runs manually but not correctly from crontab

Hello all, I'm new here and have a question if you don't mind helping me. I have a script that will work if I kick if off manually but not from Cron. My cron entry is this: 05,20,35,50 * * * * /scripts/status.sh > /dev/null 2>&1 The first script (works fine) is this: #!/bin/sh # #... (14 Replies)
Discussion started by: hs3082
14 Replies

8. Shell Programming and Scripting

Script runs manually but not correctly from crontab

Hi all I have this inside a shell script (bash): cd DIRECTORY find . -maxdepth 1 | sed 's#./##' | /usr/bin/xargs -I '{}' chown -Rv '{}' /DIRECTORY/'{}' All the directories in this location are named after usernames, so it simply sets the owner to that of the username of the folder. It... (5 Replies)
Discussion started by: fakesy
5 Replies

9. Shell Programming and Scripting

IDL job doesn't work from crontab

I have made a script to execute an IDL routine with the purpose to plot data on a fixed time. The problem is that when I include this script in the crontab to run it every night, the IDL part doesn't work (the other commands, like getting data from the database, are carried out though). This... (4 Replies)
Discussion started by: SharkM
4 Replies

10. Shell Programming and Scripting

Expect script doesn't work under crontab

Hi All, Using Expect script when I run it manually it works. But when I put the entry in crontab, the job is still running after 15 hours. The script was created as root. I don't think it's a permission issue. Any idea? This is what I have under root crontab... 00 18 * * 1-5... (4 Replies)
Discussion started by: samnyc
4 Replies
Login or Register to Ask a Question