bash functioning with command line or crontab
Hello all,
I have a strange problem with the following bash script: Code:
currentdate=`date +"%Y/%m/%d"` Then with the while-do cicle I skip some rows of the vectors read and select and index "i". For this index I evaluate the UTC time in timerefterra variable. At last I write orbitrefterra and timerefterra variables in a text file, separated by a ",". The strange thing is that if I launch the script, it works fine, but if I launch it by means of a crontab, in the output text file the variable orbitrefterra is not written. In other words I find in the file /Tasks/NewTmpPropagator/terraref.txt only the ","$timerefterra part. May you help me please? |
In your cronjob temporarily add a separate line "set -vx" or in the shebang line change for example "#!/bin/bash" to "#!/bin/bash -vx". Easiest way to troubleshoot IMO.
|
I think I would do something like:
For the user you would like to process this as su username crontab -e then add the entry # Filter Results by Todays Date Everyday at 2:23 PM. # Change Made by GianniC on 20130110 14 23 * * * cd /home/GianniC/var && cat terrafinal | awk -F, '{print $7","$2" "$3}' | grep `date +"%Y/%m/%d"` > /Tasks/NewTmpPropagator/terraref.txt 2>&1 Then save the file it will be loaded into the users crontab. This entry will run at 2:23 PM change directory into /home/GianniC/var (Whatever user you use make sure they have read and write permissions to the directory that you plan to use.) then the command to output the file in the format you would like filtering only for today's date will be run. Purest will tell you that you do not need the cat and they are correct but this is off the top of my head and I cannot think of how to exclude it. |
Quote:
|
Code:
cd /home/GianniC/var && cat terrafinal | awk -F, '{print $7","$2" "$3}' | grep `date +"%Y/%m/%d"` > /Tasks/NewTmpPropagator/terraref.txt 2>&1 And do we even need to cd to the directory first? Code:
gawk -F, '($0 ~ strftime("%Y/%m/%d")){print $7","$2" "$3}' /home/GianniC/var/terrafinal > /Tasks/NewTmpPropagator/terraref.txt 2>&1 |
Thank U all,
your suggestion give me the chance to do a correct troubleshooting! |
All times are GMT -5. The time now is 12:59 PM. |