LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   CRON Job not saving (https://www.linuxquestions.org/questions/linux-newbie-8/cron-job-not-saving-4175622942/)

trickydba 02-02-2018 10:06 AM

CRON Job not saving
 
I created a CRON job in the "/etc/cron.hourly" directory. Just to practice creating a CROn job I created a small BASH script that shows memory information and disk information:
Code:

#!/bin/bash
echo "Memory information"
free -m
echo "Disk information"
df -h

When I did a ":wq" to save it and exit, I got this error:
Code:

"CRONTEST"
"CRONTEST" E212: Can't open file for writing
Press ENTER or type command to continue

Does anybody know why I got this error?

TB0ne 02-02-2018 10:10 AM

Quote:

Originally Posted by trickydba (Post 5814825)
I created a CRON job in the "/etc/cron.hourly" directory. Just to practice creating a CROn job I created a small BASH script that shows memory information and disk information:
Code:

#!/bin/bash
echo "Memory information"
free -m
echo "Disk information"
df -h

When I did a ":wq" to save it and exit, I got this error:
Code:

"CRONTEST"
"CRONTEST" E212: Can't open file for writing
Press ENTER or type command to continue

Does anybody know why I got this error?

...because you don't have permissions to write to that directory or file???? Are you doing this as root? Because you're trying to put this into the SYSTEM CRON to run every hour. Your personal cron (which may or may not work, depending on if your administrator allows you to run cron jobs), is where you would put this.

Since you're not the systems administrator, based on what you've posted, you really should ask them for assistance with doing things that modify system files.

trickydba 02-02-2018 10:15 AM

In order to run CRON jobs hourly I would have to put them in the hourly directory right?

TB0ne 02-02-2018 10:20 AM

Quote:

Originally Posted by trickydba (Post 5814831)
In order to run CRON jobs hourly I would have to put them in the hourly directory right?

If you are the SYSTEMS ADMINISTRATOR and want these jobs to run AS ROOT every hour, yes.

If you're NOT the administrator you can't write to that directory, and you will have to schedule your OWN jobs in your OWN cron to run every hour. AGAIN, if you're not the administrator, you need to ASK THEM for assistance with these things.

AGAIN: You have been asking about cron numerous times in the past; apply what you've been told here:
https://www.linuxquestions.org/quest...er-4175608264/
https://www.linuxquestions.org/quest...hs-4175597217/

trickydba 02-02-2018 10:25 AM

Ok, I understand now. So I logged out of SUDO and tried to create a CRON job in my own directory. I gave me the same error.Also, I'm not a systems administrator.

rtmistler 02-02-2018 10:37 AM

Quote:

Originally Posted by trickydba (Post 5814836)
Ok, I understand now. So I logged out of SUDO and tried to create a CRON job in my own directory. I gave me the same error.Also, I'm not a systems administrator.

There is no logging out of sudo. Sudo is a modification to a command to give that one command root privileges. You can set it up so that it will allow you to use sudo without a password, or once the password is entered on a session you can continue to use sudo without re-entering the password, until either a timeout of the session ended.

Either case, if it is verbiage or the way each are expressing their selves we should not get overly hung up on the definition of sudo.

Instead what you should remember for this and for all cases are that when you are doing work to your system which affects the system at large, and especially if you are affecting the startup, or periodic system actions, along with working out of directories that are not your home, you should be aware that most of all those actions require superuser level privileges, however you end up obtaining them.

Therefore when you create or edit cron jobs in the future, you should remember that you'll always need to have superuser privileges.

EDIT: Although I see the concept of running a cron as a regular user is discussed in TB0ne's post. I've never done that, and probably never would try it. To me cron is used at the system level to run periodic jobs. Yes it probably can be used by a regular user, however if you have that form of maintenance requirement, I have to wonder why and what in the system is not protecting other users similarly. I.e. if it is your system alone, then I'd do it for the entire system, and thus make it as root. If it is a multi-user system, then I'd recommend to the administrator of the system that they add this for all users.

TB0ne 02-02-2018 10:46 AM

Quote:

Originally Posted by trickydba (Post 5814836)
Ok, I understand now. So I logged out of SUDO and tried to create a CRON job in my own directory. I gave me the same error.

Sorry, makes no sense at all. As a regular user, you can create any files you want in your home directory, no sudo required. With sudo, you can still create a script file in your home directory.
Quote:

Also, I'm not a systems administrator.
Right, and this has been stated numerous times in the past. And AGAIN, if you are not the systems administrator, you need to WORK WITH THEM to get this done.

MadeInGermany 02-02-2018 11:16 AM

Try the following
Code:

cd
ls -ld
/usr/bin/test -w . && echo writable || echo not writable

If writable you can place your file there.
Perhaps a subfolder is a better place
Code:

mkdir cronjobs
cd cronjobs
vi CRONTEST

Make it executable
Code:

ls -l CRONTEST
chmod +x CRONTEST
ls -l CRONTEST

Get the absolute path
Code:

pwd
Create an hourly cron job
Code:

crontab -e
like this
Code:

01 * * * * /path/to/CRONTEST
The 01 is the minute. It runs one minute past each hour.

trickydba 02-02-2018 01:16 PM

@MadeInGermany.....I tried everything you posted, in my HOME directory. It all worked just fine until I got to "crontab -e". It stated that Im not allowed to use this program (crontab).

@TB0ne...... I was in my HOME directory and wasn't sudo. I will work with them to be able to do this.

jpollard 02-02-2018 02:17 PM

Quote:

Originally Posted by trickydba (Post 5814825)
I created a CRON job in the "/etc/cron.hourly" directory. Just to practice creating a CROn job I created a small BASH script that shows memory information and disk information:
Code:

#!/bin/bash
echo "Memory information"
free -m
echo "Disk information"
df -h

When I did a ":wq" to save it and exit, I got this error:
Code:

"CRONTEST"
"CRONTEST" E212: Can't open file for writing
Press ENTER or type command to continue

Does anybody know why I got this error?

well... You don't want to do that.

If you are experimenting with cron, do it as a user.

A crontab file has 6 possible entries (man 5 crontab).
Code:

field          allowed values
-----          --------------
minute        0-59
hour          0-23
day of month  1-31
month          1-12 (or names, see below)
day of week    0-7 (0 or 7 is Sunday, or use names)

The field not shown is the command to be run.

You would do better reading the documentation on how to use cron than trying to alter your system.

trickydba 02-06-2018 08:13 AM

I didn't think I was altering the system in any way, I thought I was just showing information. I found out the reason why I could not create CRON jobs is because the password for the user 'oracle' is expired. Once the password is reset I will be able to do this.


All times are GMT -5. The time now is 09:05 PM.