Sqlplus command not found when running from crontab - linux

This is the case, I made 3 files to execute backup database command in rman
test.sh:
#!/bin/bash
sqlplus /nolog #/u01/conectar.sql
conectar.sql:
connect sys/manager as sysdba
ho rman target mydatabase/mypassword #/u01/backup.sh
backup.sh:
#!/bin/bash
RUN {backup database;}
and then I did all the chmod u+x for the files to make them executable, then export EDITOR=nano to change the cron editor.
when I go to crontab -e i put
00 15 * * * /u01/test.sh
If I clic this test.sh manually, the operation runs normally, but then in the crontab I get the "you got a mail" thing with this message
From root#localhost.localdomain Thu Dec 22 16:20:01 2016
Return-Path:
X-Original-To: oracle
Delivered-To: oracle#localhost.localdomain
Received: by localhost.localdomain (Postfix, from userid 500)
id 956CD41D4B; Thu, 22 Dec 2016 16:20:01 -0400 (AST)
From: root#localhost.localdomain (Cron Daemon)
To: oracle#localhost.localdomain
Subject: Cron /u01/test.sh
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
Message-Id: <20161222202001.956CD41D4B#localhost.localdomain>
Date: Thu, 22 Dec 2016 16:20:01 -0400 (AST)
/u01/test.sh: line 3: sqlplus: command not found"
Please can you remake the script or the crontab for me? If you can answer with the exactly modifications I would appreciate it, I'm not an expert in this environment so a general knowledge needed answer will leave me the same, thanks.

You can do it in many ways:
Just before the cron line:
PATH=$PATH:/full/path/to/oracle/bin
Or on the cron line itself:
00 15 * * * PATH=$PATH:/full/path/to/oracle/bin /u01/test.sh
Let your script test.sh source another shared script that sets up your Oracle environment:
source /path/to/oracle_env.sh
I prefer the third method because it is very flexible and it helps us keep the crontab uncluttered. .bash_profile should be meant for interactive shell only - it is not good to share it with scheduled scripts, especially in production.

Related

How to add a cron job with crontab -e

My system is centos 7.4.
After crontab -e,I add
MAILTO=root
30 4 * * * root /usr/sbin/aide --check
Then I receive email as below:
From: "(Cron Daemon)" <root#mail.mydomain.com>
To: root#mail.mydomain.com
Subject: Cron <root#myserver> root /usr/sbin/aide --check
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: <XDG_SESSION_ID=37>
X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/0>
X-Cron-Env: <LANG=en_US.UTF-8>
X-Cron-Env: <MAILTO=root>
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>
Message-Id: <20190300432001.5EC7524C51#mail.mydomain.com>
Date: Fri, 1 Mar 2019 04:32:01
/bin/sh: root: command not found
I checked /var/log/aide/aide.log is empty, there's no any information in messages and secure.It seemed my crontab script is somewhere wrong.
I just want to receive aide --check report,where is the problem?
The command you must exec is this:
MAILTO=root
30 4 * * * /usr/sbin/aide --check
Cron interpret root as command. The original cron records differ from those in cron.daily and so on directories because the standard cron records are per user, not per specific time

Crontab Job not Executing

System Date:
Wed Nov 22 02:14:54 UTC 2017
CronJob (save environment variables to file in /tmp)
02 12 * * * env > /tmp/env.txt
This job did not execute between at 02:12:00 - 02:13:00 despite being initialized at 02:10:00
The command env > /tmp/env.txt executes just fine when I do it outside of crontab. Can anyone tell me what I'm doing wrong?
You've reversed hours and minutes in your crontab file.
This should fix your problem:
12 02 * * * env > /tmp/env.txt

Run script on Startup on openSUSE

Task: Run chromium on startup on openSUSE
So far:
First I don't know what path to take, it's possible with Cron or from rc.local. I don't know which opinion is the best
Cron:
Figured out that it's not a very good idea
rc.local
So I have this script:
Fri Aug 11; 06:10:38; marton;/etc/init.d ; $ cat /etc/init.d/chrom_start.sh
#!/bin/bash
/usr/lib64/chromium/chromium
exit 0
I have permissions for the file:
Fri Aug 11; 06:11:09; marton;/etc/init.d ; $ ls -l /etc/init.d/chrom_start.sh
-rwxrwxr-x 1 root root 48 Aug 11 06:10 /etc/init.d/chrom_start.sh
openSUSE doesn't have update-rc.d
Fri Aug 11; 06:12:48; marton;/etc/init.d ; $ update-rc.d
If 'update-rc.d' is not a typo you can use command-not-found to lookup the package that contains it, like this:
cnf update-rc.d
I can't seem to find the example:
Fri Aug 11; 06:13:18; marton;/etc/init.d ; $ cat /etc/init.d/skeleton
cat: /etc/init.d/skeleton: No such file or directory
Somewhere I found that I have to use install job but it does not exist
Fri Aug 11; 06:20:35; marton;/etc/init.d ; $ %install
bash: fg: %install: no such job
So, if everything is alright, I just have to find a way to set the daemon to run on startup, what do I do next, considering that I don't have this skeleton file and these install job does not exist?
I don't know if it'll be of help on OpenSUSE, but here is a thread about "how to autostart Chromium" :
https://raspberrypi.stackexchange.com/questions/38515/auto-start-chromium-on-raspbian-jessie-11-2015
This may help too.
If you are using bash (it is the most probable scenario) you could edit your .bash_profile file, or .bash_login (both should be in your user's home directory).
You need to add at the end your chromium's path like:
/usr/bin/chromium&
the final & is to make it run as a background process. If you want to apply this change for every user you can edit your .bash_login file on /etc/skel
Hope it helps,
ps. here is an url that may help a bit.
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_01.html

I want to do a Cronjob but I got some Errors

I got some errors in my cron job and I don't know why. In my cron job is this:
and I got those errors when my cron job is trying to start my script but I don't understand Error: bad username error because mc is a valid user in my system and got the rights for the folder.
Errors:
Apr 2 21:34:55 Debian-78-wheezy-64-minimal /usr/sbin/cron[27104]: (CRON) INFO (pidfile fd = 3)
Apr 2 21:34:55 Debian-78-wheezy-64-minimal /usr/sbin/cron[27105]: (CRON) STARTUP (fork ok)
Apr 2 21:34:55 Debian-78-wheezy-64-minimal cron[27105]: Error: bad username; while reading /etc/crontab
Apr 2 21:34:55 Debian-78-wheezy-64-minimal /usr/sbin/cron[27105]: (*system*) ERROR (Syntax error, this crontab file will be ignored)
Apr 2 21:34:55 Debian-78-wheezy-64-minimal /usr/sbin/cron[27105]: (CRON) INFO (Skipping #reboot jobs -- not system startup)
You have probably corrupted your crontab file. Edit it with crontab -e and try to add an empty new line at the end.
I think the bad username it's complaining about is cd in the #reboot line.
A system crontab is like a user crontab except that you need to provide a username after the time and date fields and before the commands.
Normally there are 5 time and date fields, but they can be replaced by a single field #reboot (or #daily, #weekly, and several other options). You still need the username field.
Add a user name after #reboot (I don't know whether you want root, mc, or something else
(I'm not 100% sure of my interpretation; I haven't tried using # fields in a system crontab.)
Aside from that, it's generally a good idea to use your personal crontab, not /etc/crontab, for commands you want to run under your own account. Assuming your username is mc, you can create a file like this:
1 * * * * some_command
and then feed that file to the crontab command.
By putting personal commands in /etc/crontab, you risk messing up the rest of the file and possibly damaging the system as a whole. And you have to be root to edit /etc/crontab; don't use the root account for anything that doesn't require it.

cronjob will not start on weekday

I have to start a cronjob on every Thursday. Here is the script.
It will not start at all.
Manually it does his work but not as a cronjob.
It should start at 17.00 every Thursday:
00 17 * * 4 root cd /var/www/domein.nl/admin/scripts && php -f send_newsletter_subscribers.php
also tried to do as text: wed
33 15 * * wed root cd /var/www/domein.nl/admin/scripts && php -f send_newsletter_subscribers.php
Have no idea why it doesn't work.
Does anybody have any suggestion what I'm doing wrong?
Thanks in advance for replying.
Is this an individual user's crontab (edited with crontab -e) or a system level crontab file? If the former, then the syntax is wrong, and you need to remove the user specification ("root").
The time and date fields look fine.
Think about setting some important variables in your /etc/initab (specially PATH and SHELL).
My /etc/initab file contains the following:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/root

Resources