New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
How to run cron job one time and immediately through cPanel
MultiStars
Member
in Tutorials
Sometime i want to download a file to my cPanel account (shared hosting server), or run mysqldump or mysql import. However i don't have a SSH access and i don't want to disturb the support department. So i will need to set up a cron job and run it once time , then delete the cron job.
So, my question is, how to make the cron job run immediately? Or how to know the server time so that we can schedule the cron job to run the next minute?
The function date() in php doen't seem to be reliable/consistent with the real server time for the cron job, if i'm not mistaken.
Thanks!
This discussion has been closed.
Comments
Why do you need cronjob? Why can't you just run the php script (or whatever the cron is supposed to run) directly?
"""So i will need to set up a cron job and run it once time , then delete the cron job."""
Doesn't make sense.
Why are trying to take the scenic route? Any reason you can't simply run the script?
u can setup cron from cpanel. u dont need ssh
He said no ssh. Which to means he should find a new provider.
Yeah, as i said very clearly, there is no (jailed) ssh access since that is a typical share account. And i only need to perform those task only very occasionally. It seems i need to contact support each time i need...
Just access script?
Do not add any time or date function in PHP script.Create a cron job to run it at once per minute.It will start running after one minute and as you get desired output by script do not delete it just change its running period to long time, this will save your effort for creating cron job every time.Next time when you want to run the script again change the time to once per minute.
Cron job must be running on your server always. You need to schedule it as per your requirement. Every minute, Every day , Every week, Every month and every Year.
Or you can do it like
1) Create a status.txt file, write 1 in file
2) In script just add a check like
if(file_get_content('scripts.txt')=="1"){
// Code here
}
3) write 0 to status.txt.
Setup cron to every minute to the script. Whenever you want the script to execute, just edit file and write 1.
Unless 'system' or 'shell_exec' is not blocked.
Closed.