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.
Related
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 run a list of tests using this command: "./kaboom testlist" which is written in Python.
This command can only be excuted in the directory /e/m/user/testing3/kaboom
I want to run this command every night at midnight using a cronjob. The only examples I've found online are prewritten shell scripts. So, I am not sure how to format this into a crontab so that it does what I want.
Any suggestions?
Say you want to run a job every night at 10pm then the crontab would look like:
00 10 * * * (cd /e/m/user/testing3/kaboom ; ./kaboom testlis ) > /tmp/cronjob.log 2>&1
Crontab entry just contains the commands you want to execute.
For examples on timings please check this geekStuff link.
Get the list of active users[ users who has connected atleast once in last 6 months] in Solaris.
You could solve this by creating a script that date stamps a file somewhere when any user logs in. it could be run by the shell's system-wide init (/etc/profile for bourne compatible shells)
for instance, create a directory called /var/log/logintimes and have /etc/profile run touch /var/logintimes/$USER
then, to see the last login time, do ls -l /var/logintimes
I have a jar file that generates reports and i want to schedule to run it on every sunday,
For this purpose, i am using the crontab functionality on linux,
i have created the crontab entry using
crontab -e
45 15 * * 1 /usr/java/default/bin/java -jar /home/name/example/withouttimer.jar
but the job does not run as it should, Can you please help me find the issue with it,
Is there a way to check crontab logs?, thanks
Probably the profile used when running cron jobs does not have some variables set (JAVA_HOME? CLASSPATH?)
Do a crontab that does printenv > myfile.txt and check what is defined.
As a last test, create a .sh file and run it, that does
echo 'hello'
printenv
echo 'goodbye'
and see if redirecting the execution of your script to a log shows something.
That job runs at 3:45 pm on every monday (0 is for sunday)Are you sure you are checking it at right time?
Try running a dummy program at lesser interval to check whether its working.
Finally got the solution,
There was a couple of things that i was doing incorrectly,
The timezone of the server was different, so i had to set it accordingly.
The jar was not able to locate the input file(bad location), had to fix it.
Works gr8 now, thanks for the suggestion on adding MAILTO= , helped in debugging.
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.