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 can anyone suggest anything please? |
Quote:
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?? |
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. |
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. |
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 |
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 Code:
echo $DISPLAY 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 |
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. |
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. |
Quote:
|
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.
|
Well then. Shows how much I know... :cry:
|
It worked! w00t! Thanks again. :)
|
A quik question about describing a time with crontab
Code:
* 9 1 * 1 /home/hashbang/my_script.sh Is it possible to describe the 1st Monday of every month in crontab terms? |
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 |
It does help thanks, it seems to confirm that there is indeed no way of describing the first monday of any month in crontab.
|
All times are GMT -5. The time now is 03:17 AM. |