Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How to run cron job one time and immediately through cPanel
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.

How to run cron job one time and immediately through cPanel

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!

Comments

  • Why do you need cronjob? Why can't you just run the php script (or whatever the cron is supposed to run) directly?

    Thanked by 1Clouvider
  • gitresetgitreset Member
    edited March 2016

    """So i will need to set up a cron job and run it once time , then delete the cron job."""
    Doesn't make sense.

  • nepsneps Member

    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

  • raindog308raindog308 Administrator, Veteran

    @neps said:
    Why are trying to take the scenic route? Any reason you can't simply run the script?

    He said no ssh. Which to means he should find a new provider.

    Thanked by 1ATHK
  • MultiStarsMultiStars Member
    edited March 2016

    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...

  • shovenoseshovenose Member, Host Rep

    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.

  • HammadKhanHammadKhan Member
    edited December 2016

    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.

  • ClouviderClouvider Member, Patron Provider

    @raindog308 said:

    @neps said:
    Why are trying to take the scenic route? Any reason you can't simply run the script?

    He said no ssh. Which to means he should find a new provider.

    Unless 'system' or 'shell_exec' is not blocked. =)

  • raindog308raindog308 Administrator, Veteran
    edited December 2016

    Closed.

This discussion has been closed.