I have Plesk (or more accurately Parallels Small Business Panel) installed on my linux server. However, my knowledge of linux is pretty limited. I am trying to set up a cronjob that will run a php file.
I have found the scheduled tasks area in plesk and filled in the details for when i want the script to run e.g. 30 9 * * *. However I seem to be having difficulty writing the correct command. I am using:
usr/bin/php -q /var/www/vhosts/mywebsite.co.uk/httpdocs/admin/file_to_run.php
I have checked that the location of php is correct using:
whereis php
I have also checked that the path to the file is correct using:
find / -name 'file_to_run.php'
However the php page is not doing it's job at the specified time. Can anyone help me get to the bottom of this?
Two possibilities
1) Check if the script has an error by doing a dry run on the command line.
Because you will not see this error when the cron user runs the command.
2) Perhaps you want the output to go to a specific file?
You can redirect it as such :
usr/bin/php -q /var/www/vhosts/mywebsite.co.uk/httpdocs/admin/file_to_run.php > /your/destination/the_output
Unless your php script handles everything it needs on the inside, that is.
Related
I am running a nearly fresh image of Raspbian Stretch 4.9 with a desktop and have a program which creates a new image for the computer background every few minutes.
I am trying to create a cron job to properly update the background using pcmanfm and, having followed the suggestions here, have created the following script called update.sh to set the background:
!#/bin/bash
export DISPLAY=:0
export XAUTHORITY=/home/pi/.Xauthority
pcmanfm -w '/home/pi/folder/image.png'
The script is executable and when it is run from the terminal it functions as intended. I have created a crontab to have this run automatically as such:
* * * * * /home/pi/folder/update.sh > /home/pi/folder/log.txt 2>&1
When the cron job triggers every minute, a pop-up window appears with an error saying "Desktop manager is not active." with a button "OK" to dismiss it, and the log file reads:
** Message: x-terminal-emulator has very limited support, consider choose another terminal
I have tried the command directly in the crontab
* * * * * DISPLAY=:0 && pcmanfm -w '/home/pi/folder/image.png' > /home/pi/folder/log.txt 2>&1
And the error is different this time
Cannot open display:
I am not entirely sure what sense to make of this, though from looking around it seems cron jobs can be finnicky. I am not sure if it is a Path or environment problem because I do not know many details about these things, but I don't think it should be a problem as I am using the full path to the image and the scripts. It shouldn't be a permissions error, because I have tried this on both a user crontab and a system crontab, and both fail. (Besides, the default pi user has root permissions by default anyways.) I am not sure what else to search for or try so I am asking for help if someone could point me in the right direction or has encountered this problem before.
I had exactly the same issue, except I am running Lubuntu 17.04. It appeared lately after a recent update, though cannot pinpoint when. After lot's of research I became suspicious that one of the XDG enviromental variables must be exported too. Following some trial and error, I found that exporting XDG_RUNTIME_DIR solved the problem for me. You may want to give it a try.
To figure out the value run: echo $XDG_RUNTIME_DIR
The working wallpaper changer running from cron for me now looks like:
#!/bin/bash
...
export DISPLAY=:0
export XAUTHORITY=/home/krisz/.Xauthority
export XDG_RUNTIME_DIR=/run/user/1000
pcmanfm --set-wallpaper=${dir}/${file} --wallpaper-mode=crop
...
So I have a script that is launched on login via rc.local. The script calls a few other scripts to be launched and ran. However the console says that the file and/or directories could not be found. When I run the script manually after the login it works just fine. I have even tried to add a small delay so that I know that the system logged in. Any idea why this is and how to fix it?
Sorry if my answer is a bit vague but from what I understand is that the scripts require to be run via admin privileges. Let me elaborate, when the system starts it runs a set of specific scripts and this differs from distro to distro. Therefore, I'd check ~/.bashrc /etc/profile.dand most importantly ~/.bash_login. See what you can do there. Personally I added it here ~/.config/autostart worked fine. Don't forget to create a .desktop file.
Hope this helps
Been messing around with XAMPP Cron Jobs for awhile and can't seem to get these to work right. This is being run on my personal computer for Mac OSX Yosemite. Using the terminal to make this work. The script is a PHP file. I put the default application to open up in a browser. It runs the cron job but it opens it up as if it is a text file and not as if it is a php script.
I did test this individually script separate from the cron and it works fine. Just for testing purposes I have it just writing to basic txt file. The paths are the default that pretty much comes with XAMPP.
Example of cron job in terminal
1 * * * * /usr/bin/open /Applications/XAMPP/xamppfiles/htdocs/rest of my path/write.php
The cron job does pull up the script in the default browser but is read like a text file.
So in the URL bar it starts off with file:// and than the cron job command path listed in the example.
Two questions:
1 Is there a way to make this execute the same way if I visited the webpage?
2 Is there a way to make this run in the background?
Thanks for any input.
Running Ubuntu 14.04, and I have a script that is being run automatically when I boot the machine. For the life of me, I can't remember how or where I did this.
I already checked:
upstart (which doesn't seem to be available here, anyway)
/etc/rc.local
crontab (with #reboot)
/etc/init
/etc/init.d
.config/autostart (doesn't exist btw)
It's a script of my own, so it's not some kind of malicious virus or malware or anything. I just can't remember how I did this, and would like to know.
It has a distinct name, e.g. like ~/MyScriptXYZ.sh so I could search for that, IF I know how or where..?? (I'm a novice linux user)
A few other places you can look:
crontab -e as your own user and as root (local user crontab)
/etc/profile.d/ or /etc/profile
~/.profile
~/.bashrc
The last ditch attempt you can do is to cd / && grep -R "MyScriptXYZ" as root - this will take a while but will search all files on your computer for that reference :)
So I stumbled across this question and I managed to solve it for myself:
I was using Ubuntu (chroot) through the Linux Deploy Android app and I also couldn't find it. So to make the answer complete: Use pstree to locate and trace what is currently running and see where it's originating from.
Following Basile Starynkevitch's advice I managed to solve it by going to:
/home/[user]/.config/lxsession/LXDE/autostart and find it the code I added a while ago.
I have a process (Spark chat client) which needs to be run when my Ubuntu boots up. For this I have done followings.
I created a run.sh file which will fire up my application (and I check it's working)
I created a symbolic link from both /etc/rc5.d/ and /etc/rc3.d/ to my run.sh file. (A symbolic link is also working fine)
But my processes don't start up when my machine boots. (Is this the way to do it or am I doing the wrong thing here?)
I'm running on Ubuntu 10.04 LTS (Lucid Lynx).
Your solution would've worked in most Linux distributions. However, Ubuntu never goes past runlevel 2.
Just in case, this means the contents of rc?.d with ? > 2 are not used unless you manually raise the runlevel as root. Use rc2.d :)
The symlinks you created in /etc/rc5.d/ and /etc/rc3.d/ should be named S##name. S is for start, and the number ## gives an order in which the scripts are run.
Note also that the symlinks in these directories usually points to the actual script located in /etc/init.d/.
It looks like you want to run an X program when a user logs in, not a service on startup. Remember, in Linux there is no GUI; X is a program that runs to display graphics on the screen.
You likely want to set up a program to start on KDE/Gnome login. Each has their own way to do it, but is generally boils down to pointing at a script and saying "Run this."
Put the command to run that script in the /etc/rc.local file. I think it will run each time you log in to the system.