Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set up Cron Job on Amazon EC2 Cloud Servers

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.39k
    Comment on it

    I am writing this blog because I faced issue for adding cron jobs in Amazon Ec2 cloud server. I was using Linux 64bit .

    To add cron jobs open command prompt (via putty if windows) and login via ssh, when you are login then type:

    which php

    this will return: /usr/bin/php

    keeping response in mind from above, now type:

    #!/usr/bin/php -q

    -q parameter is passed so that whenever cron job runs, you will not get email.

    now type command:

    crontab -e

    then use vim editor to add the following lines to crontab to run your php script every minute:

    * * * * * /usr/bin/php /home/ec2-user/cron.php

    Start a php file named cron.php and enter the following contents:

    ----------------------code----------------------------
    #!/usr/bin/php -q
    <?php
    //script to test cron on adam's cloud server:
    $message = "If ur reading this then the cron job worked!!!!nn";
    
    $myFile = "testFile.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    
    fwrite($fh, $message);
    $stringData = "Yay for cloud cron! script was home/ec2-user/cron.php";
    fwrite($fh, $stringData);
    fclose($fh);
    ?>
    --------------------------------------------------------

    Now also create file testFile.txt and leave it blank. Also give this file valid permissions to write. When the cron will run, it will going to write the file.

    All done!

    Thanks for reading the blog.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: