LinuxQuestions.org
Help answer threads with 0 replies.
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-07-2008, 10:21 AM   #1
hashbangbinbash
Member
 
Registered: Mar 2008
Posts: 106

Rep: Reputation: 16
ARRGGG! Frikkin Crontab >:- ((


I'm trying to have crontab open a file on my desktop, so I did "crontab -e" and wrote in this line

Code:
15 15 * * * hashbang kwrite /home/hashbang/file.txt
I made sure file.txt is chmodded to 755, I've been setting a few minutes slater each time to test and it continues to lamentably fail. As of writing this it's 15:18, my attempt quoted above was for 15:15. From what I could google, the spaces between the integers are spaces not tabs, although I've tried with tabs as well.

can anyone suggest anything please?
 
Old 04-07-2008, 10:27 AM   #2
3rods
Member
 
Registered: Mar 2008
Posts: 70

Rep: Reputation: 16
Quote:
Originally Posted by hashbangbinbash View Post
I'm trying to have crontab open a file on my desktop, so I did "crontab -e" and wrote in this line

Code:
15 15 * * * hashbang kwrite /home/hashbang/file.txt
I made sure file.txt is chmodded to 755, I've been setting a few minutes slater each time to test and it continues to lamentably fail. As of writing this it's 15:18, my attempt quoted above was for 15:15. From what I could google, the spaces between the integers are spaces not tabs, although I've tried with tabs as well.

can anyone suggest anything please?
Just a stab in the dark, but when you type "hashbang kwrite /home/hashbang/file.txt" on the command line, does it do anything?

I don't know what hashbang is, but don't you want to "hashbang >> /home/hashbang/file.txt"?? Append output from hashbang to file.txt??

Last edited by 3rods; 04-07-2008 at 10:44 AM. Reason: added
 
Old 04-07-2008, 10:37 AM   #3
hashbangbinbash
Member
 
Registered: Mar 2008
Posts: 106

Original Poster
Rep: Reputation: 16
yeah, I tested the command first..

version 1: "/home/hashbang/file.txt" didn't work

version 2: "kwrite /home/hashbang/file.txt" did work

then looking at an example I fiound in google I came up with version 3: "hashbang /home/hashbang/file.txt" which also failed to work. That's when I came here, but thinking about it... probably best to go back to version 2, it didn't work from crontab but at least I know it works on the command line. By the way, there are no error messages produced... this is a Debian system I'm using, but I can't find any kind of error log for crontab.
 
Old 04-07-2008, 10:43 AM   #4
3rods
Member
 
Registered: Mar 2008
Posts: 70

Rep: Reputation: 16
What are you trying to do? I don't know what hashbang is (other than "#!" - hash bang), so I'm kind of lost.

If you're just trying to pipe output from stdout to a file, why not use ">"?

Like: ls -l > file.txt

Touch file.txt or use vim to create it first.
 
Old 04-07-2008, 10:50 AM   #5
hashbangbinbash
Member
 
Registered: Mar 2008
Posts: 106

Original Poster
Rep: Reputation: 16
hashbang as in me the user (hashbangbinbash, it amused me to call myself that on here, also makes for an effective method of reminding myself how to start a bash script). I was following the format described in some guide I found. So in other words

Code:
15 15 * * * user kwrite /home/user/file.txt
I only want the file to open on my desktop as a kind of reminder. Once I get the above example working, I'll know I can have the file open every monday at 9:30, then add another that emails the file every monday at lunchtime. Babysteps first though.

Last edited by hashbangbinbash; 04-07-2008 at 10:52 AM.
 
Old 04-07-2008, 11:06 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Take in mind that crontab jobs have a very limited environment, that is a limited PATH and no information about your current shell environment. You're trying to launch an application which uses a graphical user interface, but crontab does not know where to open it (on which screen). You have to explicitly specify the DISPLAY as in
Code:
15 15 * * * env DISPLAY=:0.0 /usr/bin/kwrite $HOME/file.txt > $HOME/cron.log 2>&1
The first part of this command "env DISPLAY=:0.0" set the current display to be used from the subsequent command. Check if your display is set to :0.0 by simply
Code:
echo $DISPLAY
if not, modify it accordingly. Also note that I used the full path for the command "/usr/bin/kwrite". Finally, at the end I added redirection of both standard output and standard error to a file in your home directory "$HOME/cron.log". This is useful for debugging purposes.

If you don't explicitly redirect standard output and/or standard error to a file, any message generated by the cron job will be delivered to the user by mail. Maybe you already have got mails with error messages. You can check with the command
Code:
mail
Also note that the username in the crontab is not really necessary if the crontab belongs to the user himself.
 
Old 04-07-2008, 11:07 AM   #7
3rods
Member
 
Registered: Mar 2008
Posts: 70

Rep: Reputation: 16
Ah, ok.

I don't think the user is required. If it is, it's in the wrong place. It would be after the kwrite. For instance, in Gnome to launch gedit, I could use "gedit %U" and that would launch gedit for my current user. It should be the same for kwrite, just drag the icon to the top taskbar and click on it's properties to see the command line args use to launch it.

If this worked:
version 2: "kwrite /home/hashbang/file.txt"

I would just stick with that, unless you're having an issue with passing the user value.
If so, change it to "kwrite %U /home/hashbang/file.txt" and see if it works.
 
Old 04-07-2008, 11:07 AM   #8
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
cron runs jobs in the background. It runs all the time, and cannot be sure that any user will be logged in at a given moment. cron is often used on machines which don't even have a graphical display.

kwrite is a KDE application and can only run when there is a user logged in to an X session.

There is a way to accomplish what you want to do using cron, but it is not the proper approach. It is not the intended purpose of cron to be launching X applications. cron is intended for background processes.

If you want to use kwrite, I guess you are using KDE. KDE has it's own scheduling applications which can be used to run KDE apps like kwrite. I would recommend using kalarm for this purpose. It sits in the systray and can be set up to pop up reminders, or run commands like kwrite.
 
Old 04-07-2008, 11:11 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by matthewg42 View Post
There is a way to accomplish what you want to do using cron, but it is not the proper approach. It is not the intended purpose of cron to be launching X applications. cron is intended for background processes.
I agree... I should have mentioned that. Thanks, matthew.
 
Old 04-07-2008, 11:16 AM   #10
hashbangbinbash
Member
 
Registered: Mar 2008
Posts: 106

Original Poster
Rep: Reputation: 16
Thanks guys for the variety of answers, even if crontab is not best suitable for this purpose it's still good to learn about the limits and how to overcome them. Might look for kalarm, but as a point of principal and education I think I shall ram this through with crontab. Teach linux who's boss.
 
Old 04-07-2008, 11:20 AM   #11
3rods
Member
 
Registered: Mar 2008
Posts: 70

Rep: Reputation: 16
Well then. Shows how much I know...
 
Old 04-07-2008, 11:22 AM   #12
hashbangbinbash
Member
 
Registered: Mar 2008
Posts: 106

Original Poster
Rep: Reputation: 16
It worked! w00t! Thanks again.
 
Old 04-14-2008, 12:28 PM   #13
hashbangbinbash
Member
 
Registered: Mar 2008
Posts: 106

Original Poster
Rep: Reputation: 16
A quik question about describing a time with crontab

Code:
* 9 1 * 1 /home/hashbang/my_script.sh
Does this mean my_script will run at 9 o'clock on the first monday of the month or will my_script be run only when the first day of a month is a monday?

Is it possible to describe the 1st Monday of every month in crontab terms?

Last edited by hashbangbinbash; 04-14-2008 at 12:31 PM.
 
Old 04-14-2008, 12:47 PM   #14
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
No, it means your script will run every Monday AND the first of each month (whether Monday or not). The day fields in cron are backwards in that every other field is combined with AND, but those two are combined with OR. The above translates to:

if ((the minute is any) && (the hour is 9) && (the month is any) && ((the day of month is 1) || (the day of week is 1))) run the command.

HTH

Forrest
 
Old 04-14-2008, 12:55 PM   #15
hashbangbinbash
Member
 
Registered: Mar 2008
Posts: 106

Original Poster
Rep: Reputation: 16
It does help thanks, it seems to confirm that there is indeed no way of describing the first monday of any month in crontab.

Last edited by hashbangbinbash; 04-14-2008 at 12:57 PM.
 
  


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
Crontab kalinchuk Linux - Networking 1 02-22-2006 10:59 AM
crontab -e hoover93 Linux - Newbie 2 08-06-2004 05:05 PM
knoppix wont burn..read error...arrggg virtual_rose Linux - Software 4 01-22-2004 11:33 PM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 01:35 PM
Crontab Help dvong3 Linux - General 2 08-27-2003 02:12 PM


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