LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-02-2018, 10:06 AM   #1
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Rep: Reputation: Disabled
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?
 
Old 02-02-2018, 10:10 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,681

Rep: Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971
Quote:
Originally Posted by trickydba View Post
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.

Last edited by TB0ne; 02-02-2018 at 10:12 AM.
 
Old 02-02-2018, 10:15 AM   #3
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
In order to run CRON jobs hourly I would have to put them in the hourly directory right?
 
Old 02-02-2018, 10:20 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,681

Rep: Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971
Quote:
Originally Posted by trickydba View Post
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/

Last edited by TB0ne; 02-02-2018 at 10:25 AM.
 
Old 02-02-2018, 10:25 AM   #5
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
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.
 
Old 02-02-2018, 10:37 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by trickydba View Post
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.

Last edited by rtmistler; 02-02-2018 at 11:16 AM.
 
Old 02-02-2018, 10:46 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,681

Rep: Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971
Quote:
Originally Posted by trickydba View Post
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.
 
Old 02-02-2018, 11:16 AM   #8
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,806

Rep: Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207
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.
 
Old 02-02-2018, 01:16 PM   #9
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@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.
 
Old 02-02-2018, 02:17 PM   #10
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by trickydba View Post
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.
 
Old 02-06-2018, 08:13 AM   #11
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron job starts 6 hours late, rest of cron jobs work fine pieterhouwen Linux - Newbie 33 10-05-2015 12:38 PM
Cron Job Not Running - Looks Like Cron Tried Noble User Linux - Newbie 7 10-26-2014 10:26 AM
how to abort cron if the previous cron job not yet finished? Winanjaya Linux - Newbie 2 05-22-2012 06:44 PM
linux cron job duplicate job question cpthk Linux - Newbie 4 09-11-2009 08:52 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration