LinuxQuestions.org
Visit Jeremy's Blog.
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 09-23-2013, 02:53 AM   #1
Ankush Seth
LQ Newbie
 
Registered: Sep 2013
Posts: 20

Rep: Reputation: Disabled
setup and run a cron job


Hello all i am new with crontab and jobs, but after surfing over net i am able to do this
1. i created a text file "demo.txt" with content 1 * * * * /demo.sh
for making an entry of every minute in cron job.
2.In demo.sh i wrote "echo hello world"
3. Now when i run using crontab demo.txt



Now the problem is that no message is shown to the terminal.
and for that i modified the text file with
1 * * * * /demo.sh >/dev/pts/1 2>&1
but problem is again same i can't see any message.

please tell me if i am doing the right thing or what i am missing.
I will be thankful to you!
 
Old 09-23-2013, 03:43 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273
by default crontab does not use terminal (there is no associated tty), so that echo is pointless.
redirecting the output to /dev/pts/1 may or may not work, depending on the permissions (for example the cron job may have no access right to that terminal) and of course /dev/pts/1 may or may not exist.
 
Old 09-23-2013, 10:55 AM   #3
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
you could also echo >> foo.log inside your demo.sh and then via CLI tail -f /path/to/foo.log and every min. it should populate with a new line. you could even add a time stamp to each line so you know exactly how well your practice with cron is working.

Code:
#!/bin/bash

dtstamp="`date +%F-%A-%H.%M.%S `"
log="/path/to/log/file/demo.log"

echo "Hello world @ ${dtstamp}." >> ${log}

exit
something like that. it still will not print Hello world to your terminal window, but if you tail it, you will see it and also see the exact date stamp...

Code:
[user@user ~]$ dtstamp="`date +%F-%A-%H.%M.%S `"
[user@user ~]$ echo "Hello world @ ${dtstamp}."
Hello world @ 2013-09-23-Monday-10.53.55.
hope that helps.
 
Old 09-23-2013, 02:42 PM   #4
jitendra.sharma
Member
 
Registered: Mar 2013
Location: ahmedabad
Distribution: CentOS, Ubuntu, Debian
Posts: 92
Blog Entries: 1

Rep: Reputation: Disabled
simple as that

#crontab -e

1 * * * * /bin/sh /demo.sh
 
  


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
Debian daily cron job won't run, but does run in cron.hourly. sandersch Linux - General 7 05-24-2012 02:50 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
Can't get a cron job to run derzok Linux - General 10 12-16-2007 05:00 AM
how to run this cron job ashley75 Linux - General 5 05-24-2004 12:20 PM
Did my Cron job run? ryedunn Linux - Newbie 2 02-25-2004 09:59 AM


All times are GMT -5. The time now is 04:57 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