Find the answer to your Linux question:
Results 1 to 10 of 10
The panel i use for my hostign doesnt allow me to put the full cron job command there but instead they want me to point a file to run. I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2012
    Posts
    54

    Question How to save and run a cron job from a file?


    The panel i use for my hostign doesnt allow me to put the full cron job command there but instead they want me to point a file to run.

    I want to run below command from a file. How can i do it?

    mysqldump --opt -Q -u USERNAME --password=PASSWORD DBNAME | gzip > /public_html/Daily/ukdb.gz

  2. #2
    Just Joined!
    Join Date
    Sep 2012
    Posts
    14
    this may help try this :
    Code:
    # install CRONTAB if crontab is writable
    CRONTAB="/etc/crontab"
    [ -w \$CRONTAB ] || exit
    
    grep -q "program" \$CRONTAB ||
    echo "# About the Program
    # this cron job is for 5 minutes
    */5 * * * * root /file/path/file.sh  
    " >> \$CRONTAB && killall -1 cron crond 2>/dev/null
    echo "Modified /etc/crontab"
    
    	};
    	# Bye
    	exit(0);
    }

  3. #3
    Just Joined!
    Join Date
    Aug 2012
    Posts
    54
    Quote Originally Posted by sureshk View Post
    this may help try this :
    Code:
    # install CRONTAB if crontab is writable
    CRONTAB="/etc/crontab"
    [ -w \$CRONTAB ] || exit
    
    grep -q "program" \$CRONTAB ||
    echo "# About the Program
    # this cron job is for 5 minutes
    */5 * * * * root /file/path/file.sh  
    " >> \$CRONTAB && killall -1 cron crond 2>/dev/null
    echo "Modified /etc/crontab"
    
    	};
    	# Bye
    	exit(0);
    }
    I didnt understand anything from this.
    Should i create a file with these codes?
    What should i format that file as?
    Where is the path to put the backup file?

    Oh maybe you got confused and think i have a VPS and console. Ummm, no. I have a shared hosting with no support

  4. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    Quote Originally Posted by Website View Post
    The panel i use for my hostign doesnt allow me to put the full cron job command there but instead they want me to point a file to run.

    I want to run below command from a file. How can i do it?

    mysqldump --opt -Q -u USERNAME --password=PASSWORD DBNAME | gzip > /public_html/Daily/ukdb.gz
    So how it works is you just give them a script and tell them you want it to be a cron, and when to run, and they take it and cron it for you?

    or do you actually supply them a cron-formatted job file, complete with the date/time notation of when to run?

    If the first scenario, just create a file, call it "cron-script.sh", and in it put:

    Code:
    #!/bin/bash
    mysqldump --opt -Q -u USERNAME --password=PASSWORD DBNAME | gzip > /public_html/Daily/ukdb.gz
    then make the script executable:

    Code:
    chmod +x cron-script.sh
    you can run it, to make sure it works:

    Code:
    ./cron-script.sh
    then fork it over to the hosting admins...

  5. #5
    Just Joined!
    Join Date
    Aug 2012
    Posts
    54
    I get "No Support" from hosting company because its free hosting.
    I tried the cron-script.sh solution but nothing happened.

    You can check out the panel and the services in 1freehosting.com
    There is a cronjob option but you need to give the file path for it.

  6. #6
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    i visited the site but did not see a way to view the cron function (w/o signing up). does the website give you any instructions about using the cronjob? How do you know it is not working? Do you get real-time feedback or a log or what?

  7. #7
    Just Joined!
    Join Date
    Aug 2012
    Posts
    54
    Quote Originally Posted by atreyu View Post
    i visited the site but did not see a way to view the cron function (w/o signing up). does the website give you any instructions about using the cronjob? How do you know it is not working? Do you get real-time feedback or a log or what?
    Well i assume if its there, its working. Why would they put it there if its not working. Attached is the ss
    Attached Images Attached Images

  8. #8
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    ah, so it looks like it is expecting to run a php script (i think), based upon that top line in your ss:

    Code:
    Command to run: php -f /home/blah/[ ]
    can you confirm that?

    anyway "php -f" means pass a file to php to parse it (and suppress HTTP header output).

  9. #9
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    so if that's the case, you could make a PHP script, called "mysql-cron.php" and in it put:

    PHP Code:
    <?php
    system
    ('mysqldump --opt -Q -u USERNAME --password=PASSWORD DBNAME | gzip > /public_html/Daily/ukdb.gz');
    ?>

  10. #10
    Just Joined!
    Join Date
    Aug 2012
    Posts
    54
    Quote Originally Posted by atreyu View Post
    so if that's the case, you could make a PHP script, called "mysql-cron.php" and in it put:

    PHP Code:
    <?php
    system
    ('mysqldump --opt -Q -u USERNAME --password=PASSWORD DBNAME | gzip > /public_html/Daily/ukdb.gz');
    ?>
    Good idea. Trying. Will let you know

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •