Need assistance to define path on a script which cron will execute


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need assistance to define path on a script which cron will execute
# 1  
Old 05-23-2018
Need assistance to define path on a script which cron will execute

I have written a script to execute some sql statement via executable file.

It is working fine via command line, however when I schedule it in cron.

The executable file is looking for library file in its root directory.

Wonder where does cron run the script from, and can we get the script to get the "jobs" run in a directory that we define. Thanks.

I've tried below and is still failing
Code:
* * * * * cd /path/execdir && /path/execdir/script.sh

I even put the path in the script, but still it is not working.

Code:
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/o/b/utility/bin


Last edited by rbatte1; 05-24-2018 at 01:39 PM.. Reason: Added CODE tags
# 2  
Old 05-23-2018
Hi,

I don't think it's problem with path instead some command which is being used in the script. The command path might be available to ur shell but not to from.
# 3  
Old 05-23-2018
Yeah? So how do I get the cron to also use my environment when running using command line as opposed to when it runs in cron.
# 4  
Old 05-23-2018
. /etc/profile ; rest of stuff perhaps.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 05-23-2018
Quote:
Originally Posted by jaapar
Yeah? So how do I get the cron to also use my environment when running using command line as opposed to when it runs in cron.
I found the fix, what I did was execute the user's bash_profile in the script or in cron for e.g.

Code:
0 10,22 * * * . $HOME/.bash_profile && /root/auto/generate_rpt.bash.

above fixed it for me.

Thanks.

Last edited by rbatte1; 05-24-2018 at 01:40 PM..
This User Gave Thanks to jaapar For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

cannot execute sqlplus in shell script under cron

Hi, I have a bourne shell script that needs to login into sqlplus and execute a stored procedure. I need this shell script to be run under a user crontab. It works fine if run under normal shell prompt. But it gave error message in my log file when run under crontab: SQL*Plus: Release... (4 Replies)
Discussion started by: joe_x
4 Replies

2. UNIX for Dummies Questions & Answers

Highlight directories in path with execute permission for others

Hi all, I'm trying to make a script that takes at the most one argument and lists all directories in the path in a special format: User Group Other Filename rwx r-- r-x \ rwx r-x r-- home This is my code as it is... (1 Reply)
Discussion started by: Trinimini
1 Replies

3. Shell Programming and Scripting

Difference between using shell or cron to execute a script

Hi! Maybe i am here in the wrong section for the problem, but let me try to explain. I have the following simple backup script, as a solution till the final backup solution is online. Unfortunatly it will only work when executed manually. When i set up a cron job to execute the script, only the... (4 Replies)
Discussion started by: locutus01
4 Replies

4. Solaris

anomalous behaviour when I execute the script via cron

Hi , I am having a strange problem with my cron job : here is the script that I am scheduling from cron WrapperScript.ksh #!/bin/ksh ########## Global Variables ########## DATE=$(date +"%b-%d-%y") TIME=$(date +"%H:%M") LOGFILE=sonar_execution_$DATE.log ########## Main Processing... (2 Replies)
Discussion started by: alookachaloo
2 Replies

5. Shell Programming and Scripting

Need to execute a command on a path with a space in it...

Hello, I need to execute the following command in a script: /usr/bin/ssh 205.21.1.1 vmware-cmd -v /home/virtual machines//Machine.vmx"createsnapshot Weekly_Backup >/dev/null 2>&1 The problem is that there is a space between virtual and machines and when I run the script I get no such... (2 Replies)
Discussion started by: mojoman
2 Replies

6. UNIX for Dummies Questions & Answers

cron used to execute multiple commands

have to run multiple commands at a specified time by the user... (3 Replies)
Discussion started by: hemaa
3 Replies

7. Shell Programming and Scripting

How do I define a particular dir in PATH variable and then unset that dir

How do I define a particular dir in front of PATH variable and then run some job and then at the end of job SET the PATH variable to original? in a script, WILL something like this work: ORIG_PATH=$PATH export PATH=/dir1/dir2:$PATH RUN SOME JOBS ..... unset PATH EXPORT... (2 Replies)
Discussion started by: Hangman2
2 Replies

8. Shell Programming and Scripting

cron does not execute script properly

I have a simple script that checks for certain printers and records them to a file. When I run the script manually at the command prompt, it works perfect, but when I run the script via cron, nothing happens. No errors reported, and no records are written out. I'm using Solaris 10. Below is the... (4 Replies)
Discussion started by: lmatlebyane
4 Replies

9. UNIX for Dummies Questions & Answers

a cron job needs a perl script to execute

Hello evreyone, this is my first post, and to say i'm new to this is an understatement. I know very little about perl scripts and hope some one can help me. i'm looking to get a script that a cron job can execute. what the script needs to to is 1) connect to a mysql database 2) go to a... (2 Replies)
Discussion started by: Exader
2 Replies

10. Shell Programming and Scripting

script execute by cron problem, but manual ok

Hi; I'm facing the problem with my script like below 30 0 * * * /data/SCRIPT/LOADLOGS/loadata1.sh 2 1 >> /tmp/loaddata.txt loadata1.sh calling a another 2 scripts which we need to exe in sequence. when it perform by cron jon, sometimes it just can process 20 recs or less or nothing but... (6 Replies)
Discussion started by: izai
6 Replies
Login or Register to Ask a Question