Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi guys first time here. I'm a bit discouraged. After 3 solid days of trying to get a system wide cron job to run a simple script I'm out of options. I've read many forums postings and talked to quite a few people on different IRC channels and still no cron job will seem to work.
I'm working off of PCLinuxOS 2009.1.
The goal here is to run a script to run once a day everyday. This script goes to a server and checks to see if a text file exist and if it does it executes a simple notification popup...that's all.
I want this script to run for all users. I thought it was as simple as creating the script, setting the permissions and dropping it into /etc/cron.daily
I went to /etc/crontab and check to see what the time was set to and adjusted it so that it would execute a minute or two from the time I edited the file. I saved it..and nothing.
I also tried using the GUI tool Kcron to see if what it was doing was any different from what I was doing. The only difference is that it was adding a line to crontab file. The same way it would if you created a text file with the necessary information including time and the path to the script and then running "crontab nameoffile.txt" or if you were to do a "crontab -e" and edit or add a new cron entry with the VI editor.
I'm at a complete loss as to why this simple script isn't running.
I checked to see the system processes and "crond" is running so that's fine.
The script that I dropped into the /etc/cron.daily is executable...if I click on it, it runs perfectly.
Can anybody help with this issue?
Thanks guys....any assistance on this major pain would be much appreciated.
Thanks Repo.
well I'm not really sure what I should be looking at for the log.
I checked /var/spool/cron. There's a file called info...all that was there was some entries about anacron.
Is there a list of things I should try in order? Maybe with some guidance you guys can walk me through it to see if I'm messing something up.
The cron environment is different. You don't have the same environmental variables set. So without a PATH variable, you need to use the full pathname for commands, as repo indicated.
Also, the script runs in the background without an attached terminal. So the program can't expect any input from stdin. It it writes to stdout or stderr, that output needs to be redirected to /dev/null or to a file.
Ok I'll check /var/logs/cron tomorrow on the machine that I was testing on and see if there is any feedback when the cron job ran.
Please forgive my ignorance but could explain how to get the standard output from cron?
I will also make certain that the full path is added to the script.
So what is the correct way to use cron for a system job? I ask because it seems so simple if I look in /etc/cron.daily or any other cron. folder...the scripts are there, some of them are links...the permissions equal my scripts permissions I think it should work...no?
What is the absoulute minimum line in /etc/crontab for it to "look" at the script that I have in etc/daily
This is what's there now:
# run-parts
01 * * * * root nice -n 19 run-parts --report /etc/cron.hourly
02 4 * * * root nice -n 19 run-parts --report /etc/cron.daily
22 4 * * 0 root nice -n 19 run-parts --report /etc/cron.weekly
42 4 1 * * root nice -n 19 run-parts --report /etc/cron.monthly"
Now since I'm running this as a whole system job shouldn't all I should have to do is set the time in the /etc/cron.daily line for..say 1:30 pm as
30 13 * * * root nice -n 19 run parts --report /etc/cron.daily?
Dropping a script in cron-daily was the right thing to do. Your distro set up cron, so the actual cron job is set up to run any scripts found in the folders.
It is usually the case where each script does it's own logging. If there is a log from cron, it will probably just say whether cron daily was run or not. Also check the email for root. Some cron scripts, such as for logrotate may use the /bin/logger command to log errors to the system log.
For redirecting both stdout & stderr to a file, add "> logfile 2>&" to the end of the command.
Here is a snippit from a beagle cron job. It uses the variable DEBUG to allow you to debug the script before dropping it in.
Code:
if [ "$DEBUG" = "1" ]; then
eval $COMMAND
else
eval $COMMAND > /dev/null 2>&1
fi
Something else that is often done is to group commands inside braces. That way you can redirect the output for all of the commands at once;
Ok still working on this problem. It seems simple enough to get it working but it simply won't work. I'm going to run through it again following all the advise that you guys gave me and report back later.
Are any cron jobs running? Try looking in /var/log files daemon.log and syslog for evidence. Do either of the files /etc/cron.allow and /etc/cron.deny exist? If so, what's in them?
Don't forget the following:
- Scripts dropped into /etc/cron.daily need to be set as executable
- cron's environment is limited, so use /full/path/to/command in those scripts.
Does your script run correctly if you call it directly from the terminal?
And...
Quote:
This script goes to a server and checks to see if a text file exist and if it does it executes a simple notification popup...that's all.
Oh! It "executes a simple notification popup". To which :display does this script send its output? Does it have the necessary permissions to do this?
Yes the scripts are executable and they do work when triggered from a terminal and directly from the /etc/cron.daily folder.
I've tried it with a sym link to the scipt and added the script itself to that folder and nothing so far. "crond" is running as a process on boot up so it's running.
Guys this is incredible. I'm going to set up a testing machine at home tomorrow and test the crap out of this. If you guys can think of anything else please let me know.
I'll be able to check the logs as soon as I get a fresh testing enviro. setup.
Hmmm I'm not sure about that. Well the script contains a Zenity command and a command that reads something like "notify-send -t 0 "Message Title Here" "Body of the popup message here"
But if the script runs as a single command in a terminal...and it runs when clicking on the executable script file and I don't have to tell it what display to use...why should I have to tell cron that info? Is cron really that different that it needs that info also??
Micxz the above is really all the script reads...but if you need a quote I can get that for you tomorrow
How do I tell cron what display to use? Do I actually modify the existing script to do that?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.