What all variables BY DEFAULT are available if a script is executed by the crontab on UNIX Are .profile and oracle.env executed when the cron job is executed?
What all variables BY DEFAULT are
available if a script is executed by
the crontab on UNIX Are
You can find out by yourself ( as it might vary by platform ). Write yourself a simple script that gets executed by cron and dumps all environment variables in a temp file.
Related
I have multiple scripts naming R001.r, R002.r, and so on. I need to schedule them so that they run in a sequential manner one after the other. What would be the best approach to do this.
I think you want to wrap your r scripts in a caller sh file and then invoke it through terminal. Here is what I would do.
Open up a terminal or any text editor available and fill it up with the following commands:
Rscript R0001.r
Rscript R0002.r
Rscript R0003.r
...
Save this file into something like call_my_scripts. You can then execute it via standard unix shell commands as follows:
./call_my_scripts
This will run sequentially by definition. Make sure you give exec permissions to the file before you invoke it as follows:
chmod u+x call_my_scripts
I have multiple scripts running in cron and my cron log is very flooded .
I just need to write a unix command to check if one particular scheduled script ran in last 10 minutes .
You can "touch" some file from script and check atime of this file.
Something like "touch -a /var/run/app.state" from cron script.
And for check you can use stat command with custom format to extract access time of file and calculate difference between now and this time.
I am trying to execute some sql statements using an unix script. The script is placed in crontab to run everyday at 12.00 midnight and get the output in a log file.
Though my script is running and I can see the changes in DB but the log file is not generating. However manually running the script is generating the log file. Please suggest a solution.
now=`date "+%d%m%y"`
LOG="table_partition_$now.log"
test=`sqlplus -s ${USER}/${CPWD}#${DB} << THEEND > $LOG
...
...
...
exit
This is my code snippet. Please suggest
sqlplus has no closing `
Also, can you say whether the script runs correctly outside of cron? If it only fails in cron, you may want to call
env > /tmp/mylatestslog.txt
at the start and compare the differences with your local environment. (May be differences in the user, or variables used from you personal .bashrc).
(PS. also edited the question to show one command per line.)
I am using R program to collect and update data from some local and online sources, which are updated frequently.
Since these sources are fixed, there is no argument to pass to the program, and everything is routine.
Now my supervisor wants me to set this as a scheduled daily task. I know it is impossible for .r file. Is there any way to compile the r file to executable file? such as .exe, .bat, ... ...
I don't need the executable file to be standalone, I can keep R in my computer.
any suggestion is appreciated.
You need to use the standard OS facilities (cron/at on Unix) to run R with the appropriate argument.
E.g., if you add the functions you need to .Rprofile, you can do
R --no-save --no-restore -q -e 'MyFunc(my,args)'
Alternatively, you might want to use Batch Execution of R.
For Windows I have hundreds of scripts that are set up with bat files similar to the below. It assumes that you have a NameOfScript.bat and a NameOfScript.r in the same folder and then run the .bat file from Scheduler and it logs everything from stdout/err to NameOfScript_yyyy-mm-dd.log in the same folder. I normally have the log folder seperate but adding that can be done just by changing the definition of LOG_FILE. Also passes in the folder it's in to R just in case you need to output some files in the folder.
IF DEFINED ProgramFiles(x86) (
SET R_SCRIPT="%ProgramFiles(x86)%\\R\\R-2.15.2\\bin\\Rscript.exe"
) ELSE (
SET R_SCRIPT="%ProgramFiles%\\R\\R-2.15.2\\bin\\Rscript.exe"
)
IF NOT EXIST %R_SCRIPT% GOTO FAIL
SET SCRIPT_DIR=%~dp0
SET SCRIPT_DIR=%SCRIPT_DIR:\=\\%
SET BATCH_FILE=%0
SET BATCH_FILE=%BATCH_FILE:"=%
SET SCRIPT_TO_RUN="%BATCH_FILE:.bat=.r%"
SET day=%DATE:~0,2%
SET month=%DATE:~3,2%
SET year=%DATE:~6,4%
SET yyyymmdd=%year%-%month%-%day%
SET LOG_FILE="%BATCH_FILE:.bat=%"_%yyyymmdd%.log
SET SCRIPT_DIR="%SCRIPT_DIR%"
%R_SCRIPT% --internet2 --max-mem-size=2047M --no-restore --no-save --args %SCRIPT_DIR% < %SCRIPT_TO_RUN% >> %LOG_FILE% 2>&1
PAUSE
EXIT /B 0
:FAIL
ECHO RScript not found. Failed process
You could also call the R script from C#, and run the C# project as a scheduled task.
I am executing a script manually on my UNIX system manually, it runs successfully and updated required records in ORACLE database. How ever when I exwcute the same script with crontab my process exits with the error code 127.
On analysing further, I got there is some problem in these statements.
LOGFILE=sachin
ORALOGIN=abc/abc#abcd
cmd='sqlplus ${ORALOGIN} < SQLS >> ${SVC_HOME}/LOGFILES/${LOGFILE}.date +%Y-%m-%d';
eval $cmd
Please suggest a solution
Are you sure that ${ORALOGIN} and ${LOGFILE} are valid ENV variables when cron executes the script?
Sometimes scripts that work for users don't work for cron because cron executions don't have all the ENV variables that users have.
In the interactive enviroment do
env | grep ORACLE
Long time since I've used sqlplus, but I recall it required some environment variables to function (ORACLE_HOME?) and I'm suspecting your cron job environment does not have these set.