ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
First I want to make a global picture of how my program works
I have different bash-scripts and one script that is called by cron.
The one script that is called by cron, just call all the other scripts so there must be just one entry in cron.
Now when I tested everything I did the following thing, I ran the script with the commando
Code:
/home/karel/scripts/script
and everything worked fine
and then when I wanted to test it with cron, I made the following entry in cron:
Code:
00 8,12,16,22 * * * cd /home/karel/scripts && bash script
the script ran but didn't do his "job" like it should do it.
One of the scripts makes pictures with a webcam. This scripts made a picture-file but is was 0 bytes. Then when I started to troubleshoot everything I wanted to log the output of the commando like this
Then comes the strange thing, it worked like this...
Also another script that replace text in config file with rpl, didn't worked until I logged the output...
One frequent issue with running scripts from cron is down to the fact that cron typically has a different $PATH to the user that you have been testing with.
So, two questions:
Which account did you do your testing as?
Is there any reason that you cannot run the script as that user?
After the cron executes, the output of the script is sent to the person's mail ID.
Did you check the script output to see if there are any issues ?
The output of the scripts is the following:
where I log the output of the replacing text with rpl:
Code:
Replacing "height 1024" with "height 1024" (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
But the thing is, then when I log the output it works, I wanted to log the output to see if it works and now it works
but i want to know why
-------------------------------------
Quote:
Originally Posted by Disillusionist
One frequent issue with running scripts from cron is down to the fact that cron typically has a different $PATH to the user that you have been testing with.
So, two questions:
Which account did you do your testing as?
Is there any reason that you cannot run the script as that user?
I've tested my scripts as root.
And I wanted to run my script through cron also as root
I've set the environment variables like PATH with export. So the env variables are ok, i've logged it als with "env > logfile" and I've compared with the normal env
I've tested your solution with the /bin/su and the user but then i does nothing...
it's very very strange ...
If I am understanding this right:
you mean to say that the script when the output is re-directed does not work properly whereas
when the output is not-redirected works properly.
Some of the executables use stderr to write the output. Are you sure that
in the normal shell if you do a re-direction the image converter works fine ?
Try to redirect only one stdXXX at a time.
First
script > <logfile> <- this will help just to redir the stdout
script 2> <logfile> <- only stderr
script > <logfile> 2>&1 <- both stdout and stderr
I am sure one of them must be failing and if none of these fail, I do not see any reason
why cron should not work.
No
When I redirect the ouput with "&> logfile" it works (with cron) and when remove the "&> logfile" it doesn't work properly
there are functions that works, but taking a picture with vgrabbj doens't work.
When I call the script with his absolute path, in de CLI, like this /home/karel/scripts/script then works everything
ok
i've installed mailx, and i've removed all the output logs
and now it seems also to work
but when i type mailx it's says that there is no mail for root
but when i get back as normal user "webcam" i get al the entry's
even from te first scripts, that is run as root
Quote:
webcam@Webcam:~$ mail
Mail version 8.1.2 01/15/2001. Type ? for help.
"/var/mail/webcam": 3 messages 3 unread
>U 1 root@webcam Wed May 13 19:00 101/3747 Cron <root@Webcam> cd /home/webcam && bash beveiliging/scripts/beveiligi
U 2 root@webcam Wed May 13 19:26 22/900 Cron <root@Webcam> echo $PATH
U 3 root@webcam Wed May 13 19:30 22/900 Cron <root@Webcam> echo $PATH
When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists).
Well. Now that you have found where stdout and stderr are sent, do you notice some error message in case you don't redirect the output to logfile? In post #12 you told that you "removed all the output logs and now it seems also to work". Why? What has changed from the previous attempts?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.