Script fails to run properly when run from CRONTAB


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script fails to run properly when run from CRONTAB
# 8  
Old 01-04-2014
Yes, I do want the command executed - that is intended.
the mail_report variable will have output that looks like this:
Code:
nbdeployutil --report /usr/openv/var/global/reports/20140104_044802_servername

The command is a two part command. Step one is just to run
nbdeployutil --gather
That will run for a length of time and generate several different files in a specified directory. It also spits out some output that looks like this:
Code:
NetBackup Deployment Utility, version 6.5.6_EEB1_PET2269969_SET2269958
Gathering license deployment information...
  Discovered master server servername
  Output for servername at: /usr/openv/var/global/reports/20140105_002630_servername
Gather DONE
Execution time: 15 secs
To create a report for this master server, run the following:
  nbdeployutil --report /usr/openv/var/global/reports/20140105_002630_servername

I cut out the necessary part (the part that stays "run the following") and assign it to the mail_report variable and then execute it since it is the second step of the command to run to give me the final report.

This works interactively using the script, but not through cron.
# 9  
Old 01-04-2014
You said that PATH doesn't matter. You said that when using cron, PATH is defined by:
Code:
PATH=/usr/sbin:/usr/bin

Is nbdeployutil in /usr/sbin or in /usr/bin? Or is it in /usr/openv/netbackup/bin or one of its subdirectories that is in your PATH when you run it in an environment where it works successfully?

You said your script uses absolute pathnames for everything it executes. But, nbdeployutil is not an absolute pathname.
# 10  
Old 01-05-2014
Hi Don, in this case I am using full paths in the script so the PATH environment variable doesn't come into play here. Further, the script works up to this line. I am able to tell this because the second temp file is never updated and the output file is never created. I think cron doesn't like this line
Code:
/bin/echo `$mail_report` > /tmp/nbdeployutil_temp_rpt.out

which works fine under the interactive shell.
# 11  
Old 01-05-2014
Quote:
Originally Posted by rusman
Hi Don, in this case I am using full paths in the script so the PATH environment variable doesn't come into play here. Further, the script works up to this line. I am able to tell this because the second temp file is never updated and the output file is never created. I think cron doesn't like this line
Code:
/bin/echo `$mail_report` > /tmp/nbdeployutil_temp_rpt.out

which works fine under the interactive shell.
No, no, no! The PATH environment variable absolutely DOES COME INTO PLAY here. Using back quotes (shown in red above) asks the shell being run by cron to execute the command found between those quotes. The shell has to find that command in one of the directories specified by $PATH to be able to execute it unless you use an absolute pathname. The nbdeployutil in the command you are asking the shell to execute:
Code:
nbdeployutil --report /usr/openv/var/global/reports/20140104_044802_servername

is not an absolute pathname and is not found in the directories listed in the PATH setting that is being used when you run this script under cron!

If you want this script to work under cron, you either need to change the way you set mail_report so it includes an absolute pathname for nbdeployutil or you need to set PATH so the shell being run by cron will be able to find nbdeployutil in one of the directories named in $PATH as it is set in cron's environment.

Last edited by Don Cragun; 01-05-2014 at 03:48 PM.. Reason: fix typo
# 12  
Old 01-05-2014
Holy moly, Don! I hadn't even given that any thought (obviously)! I will give that a try and let you know, but I'm feeling pretty good that this is the issue!
# 13  
Old 01-06-2014
to schedule a mail using unix command

Quote:
Originally Posted by RudiC
Are you sure the script posted does run correctly when invoked interactively? The backticks will try to execute the contents of mail_report, whatever it contains, and will probably fail, printing an error msg. Again: what is the contents of mail_report?

Hi,

Could you please help me out in scheduling a mail through Unix command.
I am using "Corntab" and "at" but not able to schedule.

I use putty for Unix.

Thanks
Vinit Raj

---------- Post updated at 06:04 AM ---------- Previous update was at 06:02 AM ----------

Hi,

Could you please help me out in scheduling a mail through Unix command.
I am using "Corntab" and "at" but not able to schedule.

I use putty for Unix.

presently i am using this command

Code:
echo "Test Mail through scheduling for 0553" | mailx -s "Check 123" xyz@abc.com | at 0553 Jan 6

Thanks
Vinit Raj
Moderator's Comments:
Mod Comment Please do not hijack a discussion concerning a different issue. If you want help with this problem, please repost this question in a new thread.

Please also use CODE tags when sample code, sample input, or sample output.

Last edited by Don Cragun; 01-07-2014 at 03:16 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string works on command-line but fails when run from shell script

I wish to replace "\\n" with a single white space. The below does the job on command-line: $ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g'; /fin/app/scripts /fin/app/01/sql However, when i have the same code to a shell script it is not able to get me the same output:... (8 Replies)
Discussion started by: mohtashims
8 Replies

2. Shell Programming and Scripting

Bash script fails when run as file

The following bash script fails with error message: "./phpquery_KNBB_html_reader.sh: line 65: syntax error near unexpected token `done'" when do ./<scriptname> in the shell. However when I copy-paste the entire contents of the file directly into a shell environment it runs ok returning the intended... (2 Replies)
Discussion started by: BurritoSolution
2 Replies

3. Shell Programming and Scripting

Script does not run properly

Hello everybody Im learning bash scrpting language and im making a script that read a file line by line and it does a comparison if in a line start with a letter or number and it will delete every ones that start with a letter. But im getting some errors First of all, this is the script's... (5 Replies)
Discussion started by: alienrunes
5 Replies

4. Shell Programming and Scripting

Script fails with ORA-20000 when run with su

Hi, I have a ksh script that runs as root ans issues several commands as a user differente from root as 'su <user> -c "command" ' . It works fine except for one step where the command executes sql statements. That command fails with ORA-20000. Now the strangest thing, if I place a read command... (5 Replies)
Discussion started by: naf
5 Replies

5. Shell Programming and Scripting

run script through crontab using ksh

hi i have a script called test.sh. the content is ls >> crontest.txt. if i run manually it's giving output.but if i scheduled in crontab it's not giving output. crontab entry: 02 * * * * /sms5/SMSHOME/eds_sh/test.sh >> /sms5/SMSHOME/eds_sh/testfile/logfile 2>&1 I am using ksh.is there... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

6. Shell Programming and Scripting

crontab fails to run script

OS is Ubuntu 8.04.3. When I run the command: /usr/bin/syslogMailer < /etc/syslog.pipes/criticalMessagesFrom a bash shell it works and i receive an email as per the script however when run from crontab it does not work. Can anyone explain why and how to fix it? /usr/bin/syslogMailer... (4 Replies)
Discussion started by: jelloir
4 Replies

7. Shell Programming and Scripting

Script not running properly when run from Crontab

Hi I am a novice Linux/Perl user and am struggling to overcome what I am sure is a simple problem. I am using a perl program to create a shell script daily containing between 10 and 30 "at -f" commands for the same day. Then I change the file attributes to allow the file to be executed. When... (2 Replies)
Discussion started by: simoncjones
2 Replies

8. Shell Programming and Scripting

How do i run a shell script without crontab.

Hi Folks, Could you please suggest me how to run a shell script on a solaris env without using crontab. I am actually trying to write a shell script which will grep "WORD" in the logfile andd sends a email.Thanks in advance. Thanks Sandeep. (3 Replies)
Discussion started by: sandeep anand
3 Replies

9. Shell Programming and Scripting

Running script that sends an html formatted email fails when its run as cronjob

Hi Im very new at working with unix and this problem I simply can not understand. I know there are a lot of threads about problems with shell scripts behaving differently when run from a terminal and from a cronjob. I have tried everything(almost) but I still havent cracked this problem. Im... (15 Replies)
Discussion started by: Nightowl
15 Replies

10. Shell Programming and Scripting

recurring run of sh script in crontab

Hello gurus. I have a problem: my crontab -e is looks like this: ORACLE_SID=bla-bla * 21 * * * (sqlplus hotback/hotback @/oracle/backups/bla-bla/scripts/hotback/daily_hotback.sql) 0 19 * * * /oracle/backups/dev10g/scripts/exports/daily_exports.sh 0 1 * * *... (4 Replies)
Discussion started by: MarGur
4 Replies
Login or Register to Ask a Question