Search code examples
linuxubuntucron

Running a cron job on ubuntu


I have a python script that generates a csv file the csv file then gets converted into an xmls file using a nodejs script and finally using an other nodejs script the xmls file gets imported to google spread sheet.

i want to be able to run a cron job that does all this one time a day automatically.

Here are the list of commands i have to use manually in order :

 1- Cd to this project director Otomoto_project_final/otomoto_final_project/otomoto 
 2- Run a python script called otomoto.py ( this will generate an output.csv file )
 3- Cd back up .. to this path Otomoto_project_final/otomoto_final_project/
 4- Run the following command : node csvtoxmls.js ( this will generate the otomoto.xlsx file) 
 5 - Run the following command : node main.js ( this will push the otomoto.xlsx file to the google spread sheet )

Solution

  • Using && you could create a one-liner cron command that would execute the commands in order (supposing all exit with no errors). For example, if you would like to run consecutive commands on 3am each day, you could add to your crontab: 0 3 * * * python3 /full/path/to/first/script/otomoto.py && node /full/path/to/second/script/csvtoxmls.js && node /full/path/main.js

    Fo extra cron configuration, you could check: https://crontab.guru/