Script problem when running on crontab

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
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/

             set DIR_HOST='SCP08'
             set DIR_ATS='/ATS'                                         
             set DIR_DEST='/backupAP'                                    
             set DIR_FILE='/etc/vfstab'                                  
             set DIR_ROUTER='/etc/defaultrouter'                         
             set DIR_IPV4='/etc/hosts'                                   
             set DIR_INT='/etc/hostname.*'                              
             set DIR_HOME='/export/home'                               
             set DIR_BANNER='/etc/motd'                                
             set DIR_PASS='/etc/passwd'                                 
             set DIR_MASK='/etc/netmasks'                             
             set DIR_GROUP='/etc/group'                                 
             set DIR_INIT='/etc/inittab'                              
             set DIR_MANIFEST='/var/svc/manifest/application/ats'      
             set DIR_GROUP='/etc/group'                                 
             set DIR_INIT='/etc/inittab'                               
             set DIR_MANIFEST='/var/svc/manifest/application/ats'       
             set DIR_PROFILE='/etc/profile'                              
             set DIR_EIS='/.profile-EIS'                                
             set DIR_BKP='/bk_tool'                                      
             set DIR_LOG='/bk_tool/log'                                  
             set DIR_CRON='/var/spool/cron/crontabs'                    

                        echo "`date +%Y%m%d_%H%M%S` Start Backup Aplicacao" >> $DIR_LOG/backup.log
                        find $DIR_ATS \( -name "*.log" -o -name "*.rtdb" \)     > $DIR_BKP/exclude_list
                        tar cXfv exclude_list - $DIR_ATS/* | gzip --stdout >$DIR_DEST/"$DIR_HOST"_aplicacao_`date +%Y%m%d`.tar.gz
                        echo "`date +%Y%m%d_%H%M%S` Fim Backup Aplicacao" >> $DIR_LOG/backup.log

                        rm -f `find $DIR_DEST -type f -ctime +3 -print`

my cron job at /var/spool/cron/crontabs/root
5 0 * * * /bk_tool/

The status of backups:

bash-3.00# ls -lh /backupAP/
total 357478
-rw-r--r--   1 root     root          20 Feb 22 00:20 SCP08_aplicacao_20140222.tar.gz
-rw-r--r--   1 root     root          20 Feb 23 00:20 SCP08_aplicacao_20140223.tar.gz
-rw-r--r--   1 root     root        174M Feb 24 18:18 SCP08_aplicacao_20140224.tar.gz

Anyone have any idea to solve this problem?
Any way to log the problem?

Moderator's Comments:
Mod Comment Use code tags, thanks. See PM.

Last edited by andredemartini; 02-25-2014 at 11:59 AM.. Reason: code tags
# 2  
This is asked very often and this is usually a problem because when the cronjob is run, it will not login with the environment that is set, when you do that manually. This also means, you will not have a $PATH or a very short list of paths in there set.
It is often recommended to use full paths in Cronjobs or have your needed environment being set/sourced at the beginning of your script.

Have a read here:
cron and crontab | Unix Linux Forums | Answers to Frequently Asked Questions
This User Gave Thanks to zaxxon For This Post:
# 3  
It worked for now zaxxon! going to correct the script on my 80 machines.

Didnt understood why that happens, once I used all full path names on my script.

But.... thats ok!! I am glade for your help!!

# 4  
Another advice, while unrelated to your original issue and not mandatory as Unix doesn't care that much file extensions, if you have a csh script (and insist using the controversial C shell for scripts), you'd better call your script backup2.csh and not
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #237
Difficulty: Easy
Paul Baran was the first to build a theoretical model for communication using packet switching.
True or False?

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

Delay in running script from crontab

I am facing an issue where sometimes crontab is running script with some delay. Below is the stmt in script and it is the only stmt in script. echo "running at `date` " >> CRONCHECK.log Below is the cron entry. 0 11 * * * Below is the time of run each day. running at Fri... (8 Replies)
Discussion started by: Nishant Singh
8 Replies

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

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

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

6. Shell Programming and Scripting

Running SQLPLUS Script in CRONTAB

Hi, Can someone please help me here with this one. This is my script: # more #!/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

7. 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/ But this does not seem to be running. Another thing to note is that,... (4 Replies)
Discussion started by: Vabiosis
4 Replies

8. UNIX for Dummies Questions & Answers

SunOs problem running crontab -e

Hi, Whenever I run crontab -e from my remote terminal logged onto a SunOS 5.6 machine I get this: root@beauvert:~> crontab -e 3495 ----- I think I have to set the terminal/editor. These are my environment variables: root@beauvert:~> set EDITOR vi PATH ... (5 Replies)
Discussion started by: mojoman
5 Replies

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

10. Shell Programming and Scripting

problem running shell script (for oracle export) in crontab

Hello Gurus, I've been tasked with solving a problem at my new job and I'm stumped. We've got a script that dynamically builds an oracle export parameter files and then runs export from the shell. it runs fine when using the shell, but will NOT run (fails in one spot everytime) when entered... (1 Reply)
Discussion started by: jsheehan223
1 Replies

Featured Tech Videos