Sponsored Content
Top Forums Shell Programming and Scripting Job runs manually, doesn't work in crontab Post 302975520 by Don Cragun on Tuesday 14th of June 2016 05:42:15 PM
Old 06-14-2016
Quote:
Originally Posted by df08388
... ... ...
I get that my problem probably has to do with setting the environment variables, but it's not clear to me yet how to do that.

"When you run the program manually and it works, what shell are you using? Change the 1st line of your script from:

Code:
shell=/bin/bash

to:

Code:
#!pathname

where pathname is the absolute pathname of the shell you are using. Does that change make your script work when run by cron ?"

Since the first line in the script is shell=bin/bash, I'm using the bash shell, right?
Yes, No, Maybe!
If the default shell for your system is /bin/bash, then having the line:
Code:
shell=/bin/bash

in your script does nothing and your script is being run by bash. If the default shell for your system is NOT /bin/bash, then having the line:
Code:
shell=/bin/bash

in your script does nothing and your script is NOT being run by bash; it is being run by the default shell on your system.

If you type the command:
Code:
shell=/dev/null

into your shell, does the shell you are using magically change to /dev/null? NO. All it does is set a shell variable that later lines in your script (or, when done interactively, in your login session) can access by testing the value of $shell.

By convention (when your login shell is not a csh derivative), when you login the shell variable SHELL is exported and set by the system to an absolute pathname of your login shell. My login shell is /bin/ksh and after I login, $SHELL expands to /bin/ksh. If I then invoke bash, $SHELL still expands to /bin/ksh. Note also that case matters: $SHELL and $shell are two different variables.

If the script you are asking cron to run is an executable file and the 1st two characters in that file are #!, the system will use the interpreter named by the pathname on the rest of that line as the program used to interpret the rest of that file.

Now, back to your environment problem...
If you don't know what environment variables /opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_export needs to have set in order for it to work correctly, you need to set all of the variables in your script to the same values that they have when you run /opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_export manually and it works.

When you login with bash as your login shell, it runs three files from your home directory if they are present: .bash_profile, .bash_login, and .profile. If those files are where the variables /opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_export needs to run are defined, the following might work for you. Change:
Code:
shell=/bin/bash

in your script to:
Code:
#!/bin/bash
HOME="/absolute/path/to/your/home/directory"
cd "$HOME"
[ -f .bash_profile ] && . .bash_profile
[ -f .bash_login ] && . .bash_login
[ -f .profile ] && . .profile

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. And, as we have repeatedly said, without knowing what /opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_export is doing, we are just guessing. If /opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_export tries to open your controlling terminal for some reason, it might just not be possible to run /opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_export from cron at all.
 

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 05:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy