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 04-11-2021, 02:57 PM   #1
newheart42108
LQ Newbie
 
Registered: Apr 2021
Posts: 5

Rep: Reputation: Disabled
crontab -e command locks up terminal


I am trying to make cron jobs work, and several sources online said to use the command crontab -e to view the cron table. However, when I try to do so, the terminal hangs up.

How do I a) prevent this from happening, and b) unlock the terminal when it does?

This is on a CentOS server.
 
Old 04-11-2021, 08:08 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
No clue as to what's happening/not happpening, but some troubleshooting questions come to mind:

When you enter the command, does an editor appear?

If you have not previously specified a crontab editor, are you asked to pick one?

Is there an error message, or does the terminal just freeze and become unresponsive?
 
Old 04-11-2021, 09:15 PM   #3
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
A wild guess: Does pressing the keys "Esc", ":", "q" and finally Enter perhaps unlock the terminal?

 
1 members found this post helpful.
Old 04-11-2021, 11:04 PM   #4
newheart42108
LQ Newbie
 
Registered: Apr 2021
Posts: 5

Original Poster
Rep: Reputation: Disabled
@frankbell - no, the cursor disappears in the Terminal window and the terminal is unresponsive.
@serOlmy - I don't have access to the server right now, but I will check your suggestion in the morning.
 
Old 04-12-2021, 02:23 PM   #5
newheart42108
LQ Newbie
 
Registered: Apr 2021
Posts: 5

Original Poster
Rep: Reputation: Disabled
I have removed all the user cron jobs and that has eliminated the cron -e problem. One of them obviously is seriously malformed.

I set up a minimal cron script
Code:
#!/usr/bin/php
<?php
date_default_timezone_set('America/Chicago');
echo "This is the output on " . date("M j, ") . 'at ' . date("G:i:s") .'<br>';
?>
This script displays the echo on screen as intended when I run it in a browser.

The cron job is
Code:
* * * * * /home/orgamya/public_html/develop/cronTest.php > /home/orgamya/public_html/develop/logs/testlog.log 2>%1
a look at tail /var/log/cron shows that the script has been called, but the output is not seen in testlog.log. crontest.php has permission 744 and testlog has permission 644.

What have I missed?
 
Old 04-12-2021, 08:28 PM   #6
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
Quote:
I have removed all the user cron jobs and that has eliminated the cron -e problem. One of them obviously is seriously malformed.
Nice catch!

Unfortunately, I don't know enough to answer your follow-up question.
 
Old 04-12-2021, 08:46 PM   #7
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,
Quote:
Originally Posted by newheart42108 View Post
The cron job is
Code:
* * * * * /home/orgamya/public_html/develop/cronTest.php > /home/orgamya/public_html/develop/logs/testlog.log 2>%1
a look at tail /var/log/cron shows that the script has been called, but the output is not seen in testlog.log. crontest.php has permission 744 and testlog has permission 644.

What have I missed?
Errors are probably ending up in a file called "%1". I think you want "2>&1" not "2>%1".

Also, if you just want to view the crontab use "crontab -l" instead of "crontab -e".

Evo2.
 
1 members found this post helpful.
Old 04-12-2021, 09:07 PM   #8
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by newheart42108 View Post
I am trying to make cron jobs work, and several sources online said to use the command crontab -e to view the cron table. However, when I try to do so, the terminal hangs up.
I'm wondering if this isn't an environment setting problem.

Anyway... you can simply use "crontab -l" to view a cron table.

Another option: If "crontab -e" is acting, uh, "wonky", keep your crontab under $HOME (say, "my.crontab"), edit it there, and "submit" it using "crontab $HOME/my.crontab".

Just a thought...
 
Old 04-12-2021, 09:24 PM   #9
newheart42108
LQ Newbie
 
Registered: Apr 2021
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks, @evo2. That at least got me error messages in my log file.

Cleaning up a couple more php errors got me nearly to what I wanted:

I was under the impression that adding the shebang in the php file would allow php to be processed. This is apparently not the case. Adding the /usr/bin/php in the cron command cleared that up.
Code:
/usr/bin/php /home/orgamya/public_html/develop/cronTest.php > /home/orgamya/public_html/develop/logs/testlog.php
There appears to be no time zone "America/Chicago" for US CST in php. I'll have to research what that should be.

The last issue is that I thought that cron logs automatically appended new lines to the log file defined. Is there a command I have to add to make that happen? I am seeing the new log line overwrite what's already in the file.
 
Old 04-12-2021, 10:01 PM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
Code:
#!/usr/bin/php
<?php
date_default_timezone_set('America/New_York');
echo "This is the output on ".date("M j, ").'at '.date("G:i:s")." EDT\n";
date_default_timezone_set('America/Chicago');
echo "This is the output on ".date("M j, ").'at '.date("G:i:s")." CDT\n";
date_default_timezone_set('America/Denver');
echo "This is the output on ".date("M j, ").'at '.date("G:i:s")." MDT\n";
date_default_timezone_set('America/Los_Angeles');
echo "This is the output on ".date("M j, ").'at '.date("G:i:s")." PDT";
?>
This is the output on Apr 12, at 22:45:14 EDT
This is the output on Apr 12, at 21:45:14 CDT
This is the output on Apr 12, at 20:45:14 MDT
This is the output on Apr 12, at 19:45:14 PDT
Using PHP 7.4.16 works for me. By the way, /usr/bin/php is the command line interpreter which is different then the apache php parser module used for php web pages. When using the shebang, if the php script is executable it should be executable from a cron script as long as the other permissions are set correctly. With redirection, using a single > overwrites the file, using >> appends.
 
1 members found this post helpful.
Old 04-12-2021, 10:13 PM   #11
newheart42108
LQ Newbie
 
Registered: Apr 2021
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks to all. I hope this helps someone down the road.

@michaelk I originally had 'America/Chicago' but was shown an error. I just inserted it again and all was well. Now that I am over the frustration of getting NOTHING, I will be able to make changes and examine the results.

Oh, and BTW, changing the > to >> before the output path solved the overwrite vs append issue

Last edited by newheart42108; 04-12-2021 at 10:16 PM.
 
  


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
gdrive from crontab does'nt work , shell is ok from command line but failed from crontab sazdovskij Linux - Newbie 3 05-20-2019 12:25 PM
[SOLVED] Sparky Linux (Debian Testing) Locks Up, FF Locks Up, Have to perform Hard Shutdowns Ztcoracat Debian 17 06-30-2017 11:15 AM
[SOLVED] Problem with crontab:: command not executed properly via crontab Ankush Seth Linux - Newbie 11 11-11-2013 06:25 AM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM

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

All times are GMT -5. The time now is 04:19 AM.

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