How to set up cron job to execute bash script
I am very new to Linux. I want to set up a cron job to execute a bash script, below is what I think I shoul do after searching stuff on the Internet. I'd be much appreciated if anyone could point me out what is incorrect and anything else I need to do.
The scenario is SSH (I have access details) to the server, set up a cron job to execute a bash script at 3am every 48 hours. The bash script meant to change system current working directory to the one I specify and invoke a php script.
1. create a bash script search.txt (text file) which contains the following command. I want this bash script switch current working dicrectory to the one i specified below and invoke file sphider.php
3. create a text file, contab.txt, which contains,
5. SSH to the server
6. cd to the directory where contab.txt is stored
7. execute command: crontab contab.txt
Where you put the script doesn't matter too much - I'd probably put it in the home directory of the relevant user.
Why not edit crontab directly - use crontab -e
Make sure the script is executable (ie chmod u+x filename)
in crontab, type
0 3 */2 * * /path/to/script/sphider.php
Note that crontab uses vim commands, so type i to insert, move to the relevant line, type the above line, then escape wq (to write and quit)
You should be able to do this all through ssh
thank you for your help. If I edit crontab directly, how about the line that is meant to change the current working directory to "/home/gwcwater/public_html/sphider/admin"? where do I type that?
the reason I wanted to put them in a bash script is that I can easily edit the text file and upload it. I am afraid I won't be able to easily get the command/syntax correct if I type everything in a command window and will have to repeat it many times if i always make mistakes.
Sorry - picked the wrong name - should have said
0 3 */2 * * /path/to/script/search.txt
Had a brain fade
Thanks again, billy. I'll try it and hopefully it will work out.
|All times are GMT -5. The time now is 08:12 PM.|