Sponsored Content
Top Forums Shell Programming and Scripting Job runs manually, doesn't work in crontab Post 302975592 by Don Cragun on Wednesday 15th of June 2016 07:01:26 PM
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.)
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
All times are GMT -4. The time now is 08:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy