Variable problem in script when using crontab


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Variable problem in script when using crontab
# 8  
Old 11-15-2009
You can source your environment and get it over with like others suggest. But what seems strange is that printf is a built-in, so it seems to me the only thing in this statement that could trigger the error is the cut statement that is somehow not in /bin or in /usr/bin. What happens when you enter
Code:
which cut

on the command line?
# 9  
Old 11-15-2009
A best practice for cron jobs is to always use the full path for each command and utility unless it is a builtin. For example:
Code:
Y1=`(/usr/bin/perl -e '@y=localtime(time());printf "%04d%02d%02d",$y[5]+1900,$y[4]+1,$y[3];')`
Y2=`(/usr/bin/perl -e '@y=localtime(time()-86400);printf "%04d%02d%02d",$y[5]+1900,$y[4]+1,$y[3];')`
D1=$(printf "$Y1" | /usr/bin/cut -c 3-8)
D2=$(printf "$Y2" | /usr/bin/cut -c 3-8)

# 10  
Old 11-15-2009
Quote:
Originally Posted by fpmurphy
A best practice for cron jobs is to always use the full path for each command and utility unless it is a builtin.
I do not agree with the statement above - since it is always a bad thing to hard-code something.
Instead you might create variables holding the name of your executable or update the path. Example:
Code:
#!/bin/ksh
export PATH=${PATH}:/something
which cut
typeset BIN_CUT=/something/cut
"${BIN_CUT}" parameters

# 11  
Old 11-15-2009
Hi everyone, my script seems to be working now! Thanks for all or you for your help! It seems that I needed the #!/bin/ksh at the beginning of the script. When I enter ‘$ which cut’ I get ‘/bin/cut’. Syndex, I was just wondering, where does the output go to when I include ‘env > /tmp/env’ in the script?

I have one more question.. I am using pearl to get today’s date. The files that I am ftp-ing have today’s date as part of the filename. I was just wondering.. is there a way to :
Select all files that were created on date = today’s Date and yesterday
(Im also considering files that do not have the date as part of the file name)

Thanks so much for your help!
# 12  
Old 11-16-2009
You might want to use `find`.
You might want to use file creation time.
You might want to use file modification time.
You might assume that the files have some pre-defined name and then guess what files could exist.
You might try filtering the file list by something - if the file time/date is in the filename.
You should avoid gathering all the data in single huge directory.
You might consider collecting all the data into some database like Oracle.
You should know that filesystem is as well a some type of database.

Also - please read ISO-8601 (or at least most important parts from it). This should tell you how to use the date format... How would you know if the files are ex. log_2009-12-31.txt or maybe log_31-20-12-09-EDT.txt ? Avoid any assumptions. If you need to hard-code some date/time format then use the ISO-8601 preferred one (ex. 2009-12-31T23:59:59.012345-05:00:00)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. UNIX for Dummies Questions & Answers

Problem with a script in crontab

Hi guys, I have a shell script which i have put on crontab to run every min. Problem is that is isn't running. But if i run the script from the existing location it runs perfectly. but if i got out of the directory and run it giving the path. it doesn't work. sh script_name.sh ----... (3 Replies)
Discussion started by: nick1982
3 Replies

3. Shell Programming and Scripting

Problem with perl script on crontab

Hi everybody, I have a perl script. I want to run it as a cron job every 10 minutes. I insert the command into crontab , using crontab -e. The problem is, I didnt get any output from script inside crontab, whereas when I run it manually through 'perl myscript.pl' it running well. Here is the cron... (2 Replies)
Discussion started by: franzramadhan
2 Replies

4. HP-UX

Problem with script arguments in crontab

I have a script scheduled in cron as shown below. 16 12 * * * /users/mydir/bin/process_master.ksh `date '+%Y%m%d'` >> /users/mydir/process_master.out This script executes correctly when invoked on command line, but doesn't work the same when scheduled in crontab. Crontab is working fine... (3 Replies)
Discussion started by: mk1216
3 Replies

5. UNIX for Dummies Questions & Answers

How to retrieve the value of variable in shell script which is called by crontab

There are two files one is shell script (sample.sh) and another is configuration file (sampl_conf.cfg) configuration file contains one variable $FTP_HOME. the value of this variable vaires for user to user. If user is say jadoo then value is /home/jadoo/ftp/, for user1 - /home/user1/ftp. The... (4 Replies)
Discussion started by: jadoo_c2
4 Replies

6. Shell Programming and Scripting

environment variable in shell script called through crontab

Please help me on below.. https://www.unix.com/shell-programming-scripting/141533-retrieve-value-environment-variable-shell-script-called-crontab.html#post302442024 I'm still here. I can still see you! (0 Replies)
Discussion started by: jadoo_c2
0 Replies

7. Shell Programming and Scripting

Retrieve the value of environment variable in shell script which called from crontab

There are two files one is shell script (sample.sh) and another is configuration file (sampl_conf.cfg) configuration file contains one variable $FTP_HOME. the value of this variable vaires for user to user. If user is say jadoo then value is /home/jadoo/ftp/, for user1 - /home/user1/ftp. The... (0 Replies)
Discussion started by: jadoo_c2
0 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. Linux

Problem with crontab + bash script

Crontab: 16 14 * * * /root/bin/./empty_mail.sh >> /root/bin/log.txt L=`mailq |grep -c frozen` echo "${NUMMAIL} frozen mail to be removed from the mailq" #echo "Press Enter to continue" #read CONTINUE echo -en "-> " for i in `mailq | grep frozen | awk '{print $3}'` ; do exim4 -Mrm $i... (1 Reply)
Discussion started by: wessberg
1 Replies

10. Solaris

Unix script Problem with crontab

Hi Experts, Am facing some problems with script (Sun solaris 9). My script (sqlplus.sh)looks like this. . . ............................................... set 'date' dd=$3 export dd mon=$2 export mon yyyy=$6 export yyyy cd /oracle/P47/saparch... (8 Replies)
Discussion started by: vrjalli
8 Replies
Login or Register to Ask a Question