Running script in crontab in a specific directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running script in crontab in a specific directory
# 8  
Old 01-26-2015
Try:
Code:
PATH=$PATH:/local/mnt:/usr/sbin
export PATH

or in bash:
Code:
export PATH=$PATH:/local/mnt:/usr/sbin

# 9  
Old 01-26-2015
Have double checked the typing and it is
Code:
export PATH=$PATH:/local/mnt:/usr/sbin

but I still get "not a valid identifier."
# 10  
Old 01-26-2015
Is there a space in you PATH variable? Or did you use export $PATH instead of export PATH. Is there a space elsewhere in the export command?
# 11  
Old 01-26-2015
No, I've got
Code:
export PATH=$PATH:/local/mnt:/usr/sbin

I checked for spaces. The only space I can see if between the word export and the word PATH. At the end of the statement, there are also no spaces
# 12  
Old 01-27-2015
Have you done simple script to test ? And if it works, then problem is in the your script code. Cron env PATH is not same as you log in. Compare PATH values. Script need external commands ? PATH need include also those dirs.



Save your env and use those values also in cron env. PATH is the most important. SHELL is not important if your script first line is #!/bin/bash and your bash is in /bin directory.
Code:
echo "$PATH
export PATH" >  /local/mnt/scr/myenv

/local/mnt/scr/test1
Code:
#!/bin/bash
. ./myenv
date
echo "PATH:$PATH"
echo "0:$0"

Code:
chmod a+rx /local/mnt/scr/test1

Add line to the crontab
Code:
# run every minute
* * * * * (cd /local/mnt/scr; ./test1 ) >> /local/mnt/scr/cron.test1.log 2>&1


/local/mnt/scr/cron.test1.log include date values ...
# 13  
Old 01-27-2015
I still haven't figured this out, but is there a way to actually run a job as the cron user and see what it is seeing in terms of paths and variables? I can see the crontab is installed under root, but it is not becoming the same user (or it does not have the same environment) as I am when I run the script as root, because my script runs fine from the same location that is being triggered with the crontab.

I have tried everyone's suggestions and they have led me closer to an answer but I have not found one yet.
# 14  
Old 01-27-2015
Log in as the target user, and then run crontab -e and schedule your script. Make sure it explicitly sources your .profile or .bashrc. That should run your script under the that user; c.f. man crontab.
On some systems, there exists /etc/crontab that has an extra user field to be run under.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

CRONTAB - one python script is not running

Hi! I'm using a RaspberryPi with standard Raspbian. Currently I'm working on some sort of weather station. For now I have three python scripts - one which is updating txt files for website - update1m.py ( it will not be necessary in few next days so I'll delete it) , second one for updating... (4 Replies)
Discussion started by: bartocham
4 Replies

2. Shell Programming and Scripting

Shell scripting-I need a script which should watch a directory for a file with specific directory

I need a script which should watch a directory for a file with specific directory. If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column. The file should be moved to another directory and the a... (8 Replies)
Discussion started by: akashdeepak
8 Replies

3. Solaris

Script problem when running on crontab

Hi guys! I created a backup script that works fine when I run manually, but when I put a crontab job to execute it the result are not the expected. (not a time problem). Here is my script: bash-3.00# cat /bk_tool/backup2.sh #!/usr/bin/csh clear set DIR_HOST='SCP08' ... (3 Replies)
Discussion started by: andredemartini
3 Replies

4. UNIX for Dummies Questions & Answers

crontab not running script

Hi All, I am having the below script to be run from crontab, it it doesnt run. 1 * * * * /home/cobr_ext/test.sh > /home/cobr_ext/temp.txt when i run i manally it runs without any issues. Could please help me as to why doesnt it run the script.:( (7 Replies)
Discussion started by: abhi_123
7 Replies

5. UNIX for Advanced & Expert Users

Particular script not running through crontab

Hi, I have created the below script, set -x # Set the Path of Environment file ENV_FILE_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/bin LOG_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/log export ENV_FILE_DIR export LOG_DIR # Set Audit Environment . ${ENV_FILE_DIR}/QDM.env... (8 Replies)
Discussion started by: yohasini
8 Replies

6. Shell Programming and Scripting

Crontab not running a script

Hi, I posted this in the Solaris forum but I think this one would be more appropriate. I created a script starting with the following lines: #!/usr/bin/ksh flag=n export flag typeset -i quant=0 (...) When running it I'm getting the following 2 errors: /tmp/tstscript/testfail.ksh:... (9 Replies)
Discussion started by: Cvg
9 Replies

7. Shell Programming and Scripting

Running SQLPLUS Script in CRONTAB

Hi, Can someone please help me here with this one. This is my script: # more tosh.sh #!/usr/bin/ksh clear . /home/oracle/.profile echo "Good morning, world." export ORACLE_HOME=/u01/app/oracle/product/9.0.1 export PATH=$ORACLE_HOME/bin:/usr/local/bin export ORACLE_SID=xxxx ... (11 Replies)
Discussion started by: santoshpayal
11 Replies

8. Shell Programming and Scripting

Problem with crontab running a script

I am trying to use the CRON utility in Fedora 11 & CentOS... I intend to run a script which pops up a warning message every hour and i made the following entry using "CRONTAB -e " * * * * * sh /bin/myscript.sh But this does not seem to be running. Another thing to note is that,... (4 Replies)
Discussion started by: Vabiosis
4 Replies

9. UNIX for Dummies Questions & Answers

Getting error when running script through crontab

Hi all, I wrote small script for Solaris and when I am running it through command prompt its ok, but when I trying to run it using crontab, i am getting error like: ld.so.1: dbloader: fatal: libACE.so: open failed: No such file or directory /tmp/file.sh: line 5: 8304 Killed ... (4 Replies)
Discussion started by: nypreH
4 Replies

10. Shell Programming and Scripting

issue with running script with crontab

I am facing a strange issue while running a script(eg A) from the crontab entry the script calls one more script(eg B) within it now when i run the script A manually(with nohup) it also executes the script B (embedded inside it) as expected. but when i run the script A from the crontab entry... (7 Replies)
Discussion started by: mad_man12
7 Replies
Login or Register to Ask a Question