LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-29-2016, 02:05 PM   #1
hawkeyesc72
LQ Newbie
 
Registered: Mar 2016
Posts: 12

Rep: Reputation: Disabled
Crontab issues


So I am finally breaking the Windows chain I've known for years and starting to use Linux more, both at home and work. I am using Kali Linux (the light version) and trying to set up a simple script to run automatically using cron. I just want a simple test phrase to display on my screen every 5 minutes. When I get this to work I can change it up for the real, work-required reasons for wanting to set up automated scripts.

Filename practice.sh:
#!/bin/bash

echo
echo "Testing...testing...1...2...3..."
echo


Using crontab -e I set this:

*/5 * * * * /root/scripts/practice.sh

I can manually run the script from anywhere in the system but for some reason it's not seeming to work properly when I set it in my crontab. I've checked to see if cron daemon is working (it is), I've restarted the cron service to ensure it is working properly (not sure if this was successful because this is the first script I am trying to automate).

What am I missing? Everything I've seen online says type crontab -e, put your task in according to the proper format, then save and exit and it will work.

But it's not.

Any thoughts?

Thanks in advance!!
 
Old 03-29-2016, 03:15 PM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
cron runs tasks in the background, so if it is running the task it will not write the message anywhere you can see it. If you just want to check whether it's running or not, redirect the cron output to a file, like

Code:
*/5 * * * * /root/scripts/practice.sh >> /tmp/file 2>&1
 
Old 03-29-2016, 04:11 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137
Quote:
Originally Posted by hawkeyesc72 View Post
I am using Kali Linux.
Why? Kali is a highly specialized penetration testing distro and is not intended for daily use. You're supposed to boot into a live Kali CD, do what you need to do, then get out and back to your real distro.

Quote:
Originally Posted by hawkeyesc72 View Post
I just want a simple test phrase to display on my screen every 5 minutes.
That will not be very easy with cron. As thesnow said, cron jobs run in their own subshell in the background, not in your active shell, so you won't be able to see their output unless you redirect it to a log file and then open it up.

Last edited by suicidaleggroll; 03-29-2016 at 04:12 PM.
 
Old 03-29-2016, 06:54 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,512

Rep: Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133
It is possible to run a GUI application via cron. One way to display a message is via zenity.

*/5 * * * * env DISPLAY:=0.0 /usr/bin/zenity --info --text="Hello World\!"

Last edited by michaelk; 03-29-2016 at 06:57 PM.
 
Old 04-06-2016, 05:28 AM   #5
hawkeyesc72
LQ Newbie
 
Registered: Mar 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
My only experience with Linux so far has been with Kali since that's what we are setting up and tinkering with at work. I researched other distros and ended up installing Ubuntu since that seems to be very friendly for beginners. It's been a fun experience so far. Learning command line commands and scripting is awesome!

Quote:
Originally Posted by suicidaleggroll View Post
"Why? Kali is a highly specialized penetration testing distro and is not intended for daily use. You're supposed to boot into a live Kali CD, do what you need to do, then get out and back to your real distro."


That will not be very easy with cron. As thesnow said, cron jobs run in their own subshell in the background, not in your active shell, so you won't be able to see their output unless you redirect it to a log file and then open it up.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] crontab sh issues logspalding Linux - Newbie 3 05-09-2014 05:59 PM
[SOLVED] Problem with crontab:: command not executed properly via crontab Ankush Seth Linux - Newbie 11 11-11-2013 07:25 AM
Crontab issues FingerprintDiVA Linux - Newbie 10 02-22-2010 01:09 AM
Crontab issues with DD and NC Everlast Linux - Newbie 6 04-24-2006 02:02 PM
Crontab Issues mikeccs Linux - Newbie 4 11-29-2004 10:09 PM

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

All times are GMT -5. The time now is 06:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration