0

I am trying to run a program that runs this line of code in

screen livestream_dl -u "..." "..."

And it then starts a process of checking if an Instagram Live video is being active then Downloads it if it can find it and if not the screen terminates.

My issue is I have placed this into the cron job by adding this

*/1   *    *    *    *     screen livestream_dl "name" "igname" -p "pass"

Firstly, should I leave it as screen or without screen which would work to get the result if I were to do the same through SSH command line

Secondly, how can I improve this cron job to make sure if the Cronjob is already running then to ignore the command and check again in a minute?

Thanks very much! :)

Haroon Baig
  • 53
  • 1
  • 9
  • It would be better if you added the command to a `bash` script and then called that from within `cron` – PYA Jul 05 '17 at 20:14
  • @pyjg How could I identify whether the Screen session was still open/cron job still running? – Haroon Baig Jul 05 '17 at 20:17
  • you need to set a variable with your script and check that variable every time you run the script. when the script finishes you just toggle the variable. for instance you will only run when your variable is `True` if it is `False` you can exit. You can store this in a database/ write it to a file from your script etc. – PYA Jul 05 '17 at 20:19

1 Answers1

0

You should definitely remove screen. screen is used to make terminal session resumable from another TTY. Since a cron job is not interactive by definition you won't need it.

In order to prevent cron from starting two instances of the job at the same time you can use flock. flock will create a semaphore file on the first run. If such a file is found it will either wait for the semaphore to be removed or terminate immediately if you specify the nonblack option. The later is probably what you want.

fhossfel
  • 2,041
  • 16
  • 24