Hi, this is my first shell script. Anyway i am trying to ftp files from one machine to another. The name of the script is ifsftp_orabkp. The code is as follows:
When I try to run it using the following it works without any problems:
./ifsftp_orabkp
However when I use crontab :
45 10 * * * /home/oracle/oracle_scripts/ifsftp_orabkp >> /home/oracle/oracle_logs/ftpora.log 2>&1
ftpora.log shows the following errors:
$ cat ftpora.log
sh: /home/oracle_scripts/ifsftp_orabkp: not found
/home/oracle/oracle_scripts/ifsftp_orabkp: syntax error at line 6: `D1=$' unexpected
/home/oracle/oracle_scripts/ifsftp_orabkp: syntax error at line 6: `D1=$' unexpected
/home/oracle/oracle_scripts/ifsftp_orabkp: syntax error at line 1: `$' unexpected
/home/oracle/oracle_scripts/ifsftp_orabkp: syntax error at line 6: `D1=$' unexpected
This script is relying on the environment being set. However this is not the case if it is run from crontab. In this case probably only the PATH variable will need to be set somewhere at the beginning. It should contain the paths to all the external commands that are bing called. I do not know where your perl binary is located. Possibly this is enough:
Better put a shebang (#!) with the shell name and its full path on your first line too. It may be that the default shell is not the same as the shell this script needs to be run in. It could be that it then uses a very classic Bourne shell that does not know the $(...) construct.
Echo your env in your script and have it run from cron.
So put this at the beginning of your script
env > /tmp/env
Have that run from cron, and then post the results. This is a simple way to trouble shoot enviornment variable problems. You can compare to how its running from cron, from when you're executing it yourself.
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
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:
#!/bin/ksh
export PATH=${PATH}:/something
which cut
typeset BIN_CUT=/something/cut
"${BIN_CUT}" parameters
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)
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)