Difference of output from cron job & shell prompt
We have a script in production like:
sqlplus -s <username>/<password><<EOF
set head off
set feedback off
set numwidth 4
set serveroutput off
spool /tmp/test1.txt
prompt column1 , column2
select column1||' , '|| column2 from <table> where <condition>;
spool off;
EOF
echo "Best Regards," >> /tmp/test1.txt
echo "IT Team" >> /tmp/test1.txt
When run one time from the shell prompt, it gives the correct value like-
column1, column2
<column-1>, <column-2>
Best Regards
IT Team
But when I run it from a cron job twice the output is like-
column1, column2
<column-1>, <column-2>
Best Regards
IT Team
Best Regards
IT Team
The problem in the above output is that the bottom 2 statements,
Best Regards
IT Team
keep getting repeated the number of times when the cron job is run. If the cron job is run 3 times the set of 2 statements get repeated thrice.
I hope, I have been able to explain the problem.
Requesting a reply to my query.
Regards
Locking this duplicate post - Difference of output from cron job & shell prompt
Similar Messages
-
Back on Nov 27, Charles Minow told me how to generate an email summarizing the results of the periodic daily/weekly/monthly jobs (by the way, Charles, thanx! Works great!).
So, now I'm wondering, for cron jobs located in /var/cron/tabs/, how would one similarly generate an email to be sent to an email address of one's choice, that detailed the outcome of each such cron job?
Thanx in advance!There are several ways of doing this.
By default the output of any cron job would be mailed to the user's local mail account, so one option would be to setup mail forwarding from the system to the user's regular mail account.
The other option is to simply pipe the output of the cron task to mail, like:
1 2 * * * /path/to/your/task | mail [email protected]
Now when the specified task runs, its output will be passed to mail and sent to the specified address. -
How to suppress "exit status 0" log mail for cron job
Hello,
we have a shell script to collect stats every day. it is croned.
Recently, in the moning, get email to say "Output from cron job xxxx, in server xxx, exit status 0",
As we know, the job is done well everyday without error(exit 0), but my question is how to let server to stop sending this useless alert email everyday.
any trick?
thank you.
cc: the script
case $1 in
-? ) cat $0 | grep "#H" | grep -v "grep"
exit
esac
case $1 in
-? ) cat $0 | grep "#H" | grep -v "grep"
exit
esac
if [ -n "$1" ]; then
ORACLE_SID=$1
else
return
fi
if [ -n "$2" ]; then
SCHEMA=$2
else
return
fi
TOOLS=/opt/dba/oraadmin/tools
TABLE=xxx
COLUMN=xxx
. /opt/dba/oraadmin/tools/ora_env.sh -S $ORACLE_SID
LOG_FILE=$SVR_LOG/dbms_stats_xxx.log
echo $LOG_FILE
$ORACLE_HOME/bin/sqlplus '/ as sysdba' << !EOF > $LOG_FILE
set echo on;
exec dbms_stats.gather_table_stats('$SCHEMA','$TABLE');
exec dbms_stats.gather_table_stats('$SCHEMA','$TABLE', method_opt => 'for columns $COLUMN size 1', cascade => FALSE);
DECLARE
n_distcnt NUMBER;
v_Owner varchar2(100) := '$SCHEMA';
v_TABLE_NAME varchar2(100) := '$TABLE';
v_COL_NAME varchar2(100) := '$COLUMN';
BEGIN
select round(num_rows/3,0) into n_distcnt from all_tables where owner = v_Owner and table_name = v_TABLE_NAME;
--and then just set statistics
DBMS_STATS.set_column_stats (v_Owner,
v_TABLE_NAME,
v_COL_NAME,
distcnt => n_distcnt);
END;
exit;
EOF
Edited by: 795980 on Aug 2, 2011 7:43 AM795980 wrote:
Hello,
we have a shell script to collect stats every day. it is croned.
Recently, in the moning, get email to say "Output from cron job xxxx, in server xxx, exit status 0",
As we know, the job is done well everyday without error(exit 0), but my question is how to let server to stop sending this useless alert email everyday.
any trick?
thank you.
cc: the script
case $1 in
-? ) cat $0 | grep "#H" | grep -v "grep"
exit
esac
case $1 in
-? ) cat $0 | grep "#H" | grep -v "grep"
exit
esac
if [ -n "$1" ]; then
ORACLE_SID=$1
else
return
fi
if [ -n "$2" ]; then
SCHEMA=$2
else
return
fi
TOOLS=/opt/dba/oraadmin/tools
TABLE=xxx
COLUMN=xxx
. /opt/dba/oraadmin/tools/ora_env.sh -S $ORACLE_SID
LOG_FILE=$SVR_LOG/dbms_stats_xxx.log
echo $LOG_FILE
$ORACLE_HOME/bin/sqlplus '/ as sysdba' << !EOF > $LOG_FILE
set echo on;
exec dbms_stats.gather_table_stats('$SCHEMA','$TABLE');
exec dbms_stats.gather_table_stats('$SCHEMA','$TABLE', method_opt => 'for columns $COLUMN size 1', cascade => FALSE);
DECLARE
n_distcnt NUMBER;
v_Owner varchar2(100) := '$SCHEMA';
v_TABLE_NAME varchar2(100) := '$TABLE';
v_COL_NAME varchar2(100) := '$COLUMN';
BEGIN
select round(num_rows/3,0) into n_distcnt from all_tables where owner = v_Owner and table_name = v_TABLE_NAME;
--and then just set statistics
DBMS_STATS.set_column_stats (v_Owner,
v_TABLE_NAME,
v_COL_NAME,
distcnt => n_distcnt);
END;
exit;
EOF
Edited by: 795980 on Aug 2, 2011 7:43 AM1) problem & solution have NOTHING to do with Oracle RDBMS & is Scripting 101 Basics
2) posted script does NOT send any email so does not contribute to problem or solution.
my question is how to let server to stop sending this useless alert email everyday.The obvious solution is to NOT send the message.
code sending script to stop being a spam-o-gram generator -
What is "nmz" on cron job?
after we installed VIS demo database (R12), I found rapidinstall put one entry on cron job. Look like this job relate to concurrent manager.
0,15,30,45 * * * * JAVA_HOME=/u4/oracle/VIS/db/tech_st/10.2.0/jdk /u4/oracle/VIS/db/tech_st/10.2.0/ccr/bin/emCCR -silent start
anyone can tell me what is this process really doing?
Can I stop it?
if I remove entry from cron job, what going happen?
Thanks.According to Oracle MetaLink Doc ID 781925.1, the cron job belongs to the Oracle Configuration Manager (OCM) Collector. OCM is said to be packaged with all Oracle software distributions, including Critical Patch Updates, patch sets and product releases.
OCM documentation is available from Oracle at:
http://www.oracle.com/technology/documentation/ocm.html -
Mount USB/Firewire drive from shell or cron job
Is there a way to mount a USB/Firewire drive from the shell or possibly mount it using a cron job? Here's the situation. I have a user that keeps all of her data on her desktop or in her Documents folder. I have attached a firewire drive to her PowerMac G5 (OS 10.4.6) and successfully created cron jobs to backup her entire user folder every night. The problem is that she logs off of her computer before she leaves work. When she logs of the firewire drive unmounts and the cron job fails because it cannot find the drive. I was hoping there was a way to mount the drive using a script so that it will mount, let the cron job run, and then possibly unmount the drive afterwards. Any help with this would be much appreciated.
MacMini, PowerMac G5, iMac Mac OS X (10.4.7)Try adding the following line to the beginning of the job:
mount -a
You may need to add u and/or w to the command after the a without any additional spaces for the mount to work properly.
(13951) -
Shell Script gives error when run through cron job.
Hi,
The following shell script runs without any problem when executed manulally.
USED=$(df -h /arch | tail -1 | awk '{print $5}' | cut -d '%' -f 1)
if [ ${USED} -gt 90 ]
then
find /arch/AUBUAT/ -type f -mtime +0 | xargs rm
find /arch/AUBMIG/ -type f -mtime +0 | xargs rm
fi
But the same gives below error when called from a cron job:
/backup/arch_test.sh: syntax error at line 1: `USED=$' unexpected
We are running following version:
bash-3.00$ uname -a
SunOS uaeaubdbdr01.aub.af 5.10 Generic_141444-09 sun4u sparc SUNW,SPARC-Enterprise
Kindly assist.
Thanks
Edited by: user13362786 on Apr 20, 2011 4:36 AMHi,
When I used #!/usr/bin/sh now even the manul execution of the script fails with the same err:
bash-3.00$ ./arch_test.sh
./arch_test.sh: syntax error at line 2: `USED=$' unexpected
And when I used #!/usr/bin/ksh the manual execution runs fine but again when the script is run from cronjob it now give dirrect err:
/backup/arch_test.sh[2]: df: not found
/backup/arch_test.sh[2]: tail: not found
/backup/arch_test.sh[2]: cut: not found
/backup/arch_test.sh[2]: awk: not found
/backup/arch_test.sh[3]: test: argument expected -
How to Create Linux-Cron Job from a Java Program
Hello,
Can anybody help me to CREATE/EDIT/DELETE Linux Cron job from Java Program. Its Very Urgent.Thanks in advance..
from
ChakriI decided this didn't sound too tough so I played around with it a little. Basically because I'd never tried executing external processes out of java before, so I wanted to see how it was done.
Just change whatever you like in the jobs ArrayList and call writeJobs.
If you call writeJobs without putting anything in the list first you'll wipe out all of your crontab entries.
import java.lang.*;
import java.io.*;
import java.util.*;
public class cron {
ArrayList jobs;
Runtime rt;
cron() {
rt = Runtime.getRuntime();
jobs = new ArrayList();
void readCron() {
String[] list = { "crontab", "-l" };
jobs = new ArrayList();
try {
// Stick a job into crontab
Process child = rt.exec(list);
BufferedReader cronout = new BufferedReader(new InputStreamReader(child.getInputStream()));
String cronjob = cronout.readLine();
while (cronjob != null) {
jobs.add(cronjob);
cronjob = cronout.readLine();
child.waitFor();
catch(IOException e) {
System.err.println("IOException starting process!");
catch(InterruptedException e) {
System.err.println("Interrupted waiting for process!");
void listJobs() {
Iterator iter = jobs.iterator();
while (iter.hasNext()) {
System.out.println((String)iter.next());
void writeJobs() {
String[] edit = { "crontab"};
try {
// Stick a job into crontab
Process child = rt.exec(edit);
PrintWriter cronIn = new PrintWriter(child.getOutputStream());
Iterator iter = jobs.iterator();
while (iter.hasNext()) {
cronIn.println((String)iter.next());
cronIn.close();
child.waitFor();
catch(IOException e) {
System.err.println("IOException starting process!");
catch(InterruptedException e) {
System.err.println("Interrupted waiting for process!");
void doStuff() {
readCron();
listJobs();
jobs.add("* * * * 4 cronjob");
writeJobs();
readCron();
listJobs();
public static void main(String[] args) {
cron c = new cron();
c.doStuff();
} -
[SOLVED] Cron Job that starts every 30 minutes from boot
I wish to have a cron job that runs a script every 30 minutes from boot, without any users logging in.
I know about crontab -e, but I think that would I only run once i'm logged in. I've also heard about @reboot, but that would only run the script once.
RabbidRabbit
Last edited by rabbidrabbit (2012-01-31 20:14:13)Cron jobs will run whenever the system is up, regardless of whether or not anyone is logged in.
I don't remember the syntax, but I know that at least some cron implementations have a way to run a job every 30 minutes, starting for the first time 30 minutes after reboot.
EDIT: I just checked the syntax for fcron, which is what I use, and it seems like doing @ 30 your/command/here will make it run every 30 minutes of uptime.
Last edited by kyla (2012-01-31 00:17:30) -
Suppress cron from logging a cron job
I have a cron job that I'm running once per minute. I don't want to have the /var/log/crond.log get updated 60 times per hour. How can I suppress the logging of the job?
I've tried adding the following to the cron line but they just get logged right along with it!
*/1 * * * * /path/to/script > /dev/null
*/1 * * * * /path/to/script > /dev/null 2>&1@st - I can change the /etc/conf.d/crond to a lower level (default is CROND_ARGS="-S -l info") but I'm only interested in stopping the activity for a specific job; changing it from info to notice will be a global setting.
* debug - Debug level message
* info - Informational message
* notice - Normal but significant conditions
* warning, warn (depreciated) - Warning conditions
* err, error (depreciated) - Error conditions
* crit - Critical conditions
* alert - Action must be taken immediately
* emerg, panic - System is unusable
Last edited by graysky (2010-12-24 20:01:59) -
Running odihragent from shell prompt
Hi
I am currently trying to run odihragent from a shell prompt to do some debugging however I am not sure of the date format that it expects? Can anybody help?
/oracle/10gASR2/ldap/odi/bin/odihragent OracleHRAgent connect=find login=apps pass=*** date=200501011200
status= -1
Error - ORA-01722: invalid number
Error in OCIStmtExecute
Error in Execute
HR Agent failed with Status:2well, the problem is not with the command line arguments. it doesnt matter if we get the input from the user through command prompt or GUI. The problem is only in the handling of the change in exitValue during running.
-
Reading output from a Solaris(UNIX) shell script
Hello All, I have written some fairly large shell scripts. I have also written a simple java GUI that contains a button that will run the script. The script runs. The problem is that I cannot see the output from the script in the x-term that I used to run my java class file.
I am developing in a windows environment, I have a silly little system.out that prints "Button Pressed", which works in windows just fine but on my ultra 10 running Solaris 8 the term just sits there no output to the srceen.
Has anyone out there solved this problem or know of a way that I can? ThanksI don't know how to print out to the x-term. But you can add a JTextArea to the GUI and get the output there.
String output = null;
StringBuffer returnString = new StringBuffer();
String command = /path/to/shell/script/script.sh
process = Runtime.getRuntime().exec(command);
InputStreamReader isr = new InputStreamReader (process.getInputStream());
input = new BufferedReader(isr);
while((output = input.readLine()) != null){
returnString.append(output);
}Wouldn't a System.out.println(returnString.toString()) print to the x-term console?
hope this helps. -
Output from Run Shell Script action
Does anyone know what happens to the output of a "Run Shell Script" Automator action if there are no further actions? Does it simply get discarded, or does it end up in a log somewhere?
It's the same for any action, nothing.
The results passed on to the next action is generally just a list of file paths, or perhaps some text, or maybe a reference to a single item. In the "Run Shell Script" case, the result would likely simply be some text, perhaps as a list of lines.
So, if there are no more actions, any of those results are just dropped.
However, a list of files (or whatever) is actually just part of the results. An action performs some task on the input, or on the results from a previous action. In a sense, there can be said to be two parts to the "results". For example, perhaps an action changes some photos to black & white, so the photos will have been changed and then the paths to the photos (list of items) will be passed to the next action. The list of items is the only usable part for the next action, if there is a next action.
You can use Automator's "View Results" action after it to see the results, TextEdit's "New Text File" to create a file with the previous results as the contents, TextEdit's "New TextEdit Document" to open a new document with the results as the document's contents, and so on. -
Cron job is not working SCP automated shell script
#!/usr/bin/expect -f
# connect via scp
spawn scp "[email protected]:/u04/dumps/test.dmp" /u10/app/
expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
-re ".*sword.*" {
exp_send "pwd\r"
interact
above is the automated script to download the file from remote server to local server.
I am trying to download around 2GB file. for that i am using the above automated script. But that script is not working cron service.
Cron is not executing that script to download the file from Remote server to Local Server.Cron is not executing that script to download the file from Remote server to Local Server.That script only or any script ? Did you try with something else ?
I had a similar problem on a Linux machine, where cron jobs didn't start, and the only solution was to restart cron daemon whenever crontab files were updated. -
How to take the cron job log in HP UX?
Hi,
How to take the cron job log in HP UX
I need to run a backup and other stuff everyday. How do I check and start cron service under HP-UX UNIX operating system? How do I write cron jobs?
A. Cron service is required to run jobs and tasks such as backup.
You must login as the root to run following commands. Each user that is using the cron service must have a cron configuration file in the /var/spool/cron/crontab directory. Also users are permitted if their name appeared in /var/adm/cron/cron.allow file
Task: Find out if cron is running under HP-UX
Type the following command at a shell prompt
# ps -ef | grep cron
Open /etc/rc.config.d/cron file
vi /etc/rc.config.d/cron
Set control variable to 1 to enable cron: CRON=1
Set control variable to 0 to disable: CRON=0
Close and save the file. To start or stop cron you can type the following command:
# /sbin/init.d/cron start <-- start cron
# /sbin/init.d/cron stop <-- stop cron
Task: HP-UX Start cron service
If cron is not running, simply type:
# cron
Task: Edit / create cron jobs
Type the following command to submit a cron job:
# crontab -e
List your cron file:
# crontab -l
Backup all your cron jobs:
# crontab -l > ~/backup.cron.jobs
Remove ALL cron job:
# crontab -r
Task: Crontab file format
Cron file format is as follows:
MIN HOUR DATE MONTH DAY /PATH/TO/COMMAND
0-59 0-23 1-31 1-12 0-6 /root/scripts/backup2tape.shEasy to remember crontab file format:
* * * * * command to be executed
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)To run /root/script/backup at 23:00, every day, enter:
# crontab -e
Append following
0 23 * * * /root/script/backupRun foo job very weekday (MON-Fri) at 6am, enter:
0 6 * * 1-5 /root/script/backupFor more information refer to cron and crontab man pages.
Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.
Related Other Helpful FAQs:
What is Cron?
Linux Start and stop the cron or crond service
Run crontab Every 10 Minutes
Linux / UNIX Setup and run php script as a cron job
Stop Ubuntu / Debian Linux From Deleting /tmp Files on Boot
Discussion on This FAQDavid Says:
January 15th, 2008 at 12:21 am
You might note that all files normally found in /etc/init.d, /etc/rc*.d, and others are all in /sbin in HP-UX 10.20 and up.
Note too that your formatting is off in the description of the /etc/rc.config.d/cron file. Also, if you run /usr/bin/cron instead of /sbin/init.d/cron start, the /etc/rc.config.d/cron file is not used.
Regards,
SatyaI guess it would :)
btw, how did this piece miss from the contents pasted by the OP ?
The doc has given all details of CRON and missed where to see the logfiles. :)
****Added****
I tried man crontab in windows, i dont see it.i overlook most of the things, i would have done the same ;)
Edited by: Bobcatalog on Oct 23, 2008 9:40 AM -
Hi
I am using linux 5.x
uname -r
2.6.18-348.16.1.0.1.el5PAE
I have 2 crontab jobs set up as following .
cat backup_confluence.sh
#!/bin/bash
# bash shell script to backup confluence backups to bccpfr
# Schedule this script after the backups are performed that day
# Setup the environment for the bourne-again shell
. ./.bash_profile
# Copy the daily backups for confluence
find /usr/share/confluence/data/backups -mtime -1 \! -type d -exec ls {} \; -exec scp {} bccpfr:/usr/backup/confluence \;
second
cat backup_jira.sh
#!/bin/bash
# bash shell script to backup jira backups to bccpfr
# Schedule this script after the backups are performed that day
# Setup the environment for the bourne-again shell
. ./.bash_profile
# Copy the daily backups for jira
find /usr/share/jira/backups -mtime -1 \! -type d -exec ls {} \; -exec scp {} bccpfr:/usr/backup/jira \;
cron as following
$ crontab -l
13 06 * * * /home/lsg/backup_jira.sh
18 06 * * * /home/lsg/backup_confluence.sh
Issue
Both the above .sh are running properly when executed manually but they are not running automatically at the given time crontab job.
Kindly help me on this issue.
many thanks
JIs your crontask not running at all or is the scheduled task failing?
Hey Tommy I sent you some replies yesterday; don't know what happened to them. Yes I can see that crond runs every ten minutes. Also when I created the crontab file using the command you sent here I could see that it was running every minute by looking at root mail in /var/log.
Do you have execute permission set on the scripts?
Yes
Any info in /var/log/messages or e-mail?
Output from mail-
From root@razorback Tue Feb 11 08:19:01 2014
Return-Path: <root@razorback>
Received: from razorback (localhost [127.0.0.1])
by razorback (8.13.8/8.13.8) with ESMTP id s1BEJ154018231
for <root@razorback>; Tue, 11 Feb 2014 08:19:01 -0600
Received: (from root@localhost)
by razorback (8.13.8/8.13.8/Submit) id s1BEJ1rh018198;
Tue, 11 Feb 2014 08:19:01 -0600
Date: Tue, 11 Feb 2014 08:19:01 -0600
Message-Id: <201402111419.s1BEJ1rh018198@razorback>
From: root@razorback (Cron Daemon)
To: root@razorback
Subject: Cron <root@razorback> $(date) >> /tmp/cronout
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
/bin/sh: Tue: command not found
From root@razorback Tue Feb 11 08:20:02 2014
Return-Path: <root@razorback>
Received: from razorback (localhost [127.0.0.1])
by razorback (8.13.8/8.13.8) with ESMTP id s1BEK2BD018267
for <root@razorback>; Tue, 11 Feb 2014 08:20:02 -0600
Received: (from root@localhost)
by razorback (8.13.8/8.13.8/Submit) id s1BEK1mT018238;
Tue, 11 Feb 2014 08:20:01 -0600
Date: Tue, 11 Feb 2014 08:20:01 -0600
Message-Id: <201402111420.s1BEK1mT018238@razorback>
From: root@razorback (Cron Daemon)
To: root@razorback
Subject: Cron <root@razorback> $(date) >> /tmp/cronout
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
/bin/sh: Tue: command not found
Maybe you are looking for
-
Hi Folks, I am getting error when I create new BP and try to save it. Error is as follows. Run report CRM_MKTBP_ZCACL_UPDATE_30 first Message no. CRM_MKTPROF065 How could be the cause? Where should I run this report? What does this report stand for?
-
Print Booklet: Cannot choose Adobe PDF as printer
Hello there! I used to be able to choose "Adobe PDF" as the printer when I export my document through Print Booklet. For some reason, selecting "Adobe PDF" is no longer available. Does anyone know how I can get this option back? I believe it disappea
-
Integration third-party SMS software ?
Hello everyone, We had an SMS software which can send short messages to our customer automatically . The SMS software was developed with ASP+Sql Server . Is there possibility to integration the SMS software into Portal as part of Portal ? Is
-
Premiere Pro CC 2014 hangs up on loading importerquicktime.prm
Then it also gives the error message "could not find any capable video play modules." My system: HP Elitebook 8570P, Windows 7 Pro, 64 bit Intel Core i7-3740QM @ 2.7GHz 8G RAM, GPU: AMD Radeon HD 7500M/ 7600M Series 4G memory I've been researching t
-
How do I upload an image to a discussion?
Please tell me the steps to add a screen cap to a discuusion thread in Apple Support Communities. I have taken the screen cap (power + home buttons). I tried copying and pasting the picture from the Photos app into my discussion in my Safari Web br