In Linux, is there a way to run a cron job in the foreground (or interactive mode)? (I have a program that runs periodically to accept user input and do some processing. So
if you don't have a gui and you only have the terminal, divert the exit to tty execute ´tty´ and it will return the device to which you will redirect the output for example in Centos it will be something like / dev / pts / 0 then in crontab -e you write 1 * * * * user sh / PATH / TO / SCRIPT> / dev / pts / 0 adjust the time in crontab according to your needs. It will only run if there is someone with that terminal open
BUT WHAT PEOPLE ARE LOOKING FOR BY THE TITLE OF THE QUESTION Linux: Run cron job in foreground the answer is nohup command_to_run & 1 * * * * nohup user sh / PATH / TO / SCRIPT & nohup allows executing a script as if it were an open terminal and solves the problem of executing the crontab. I mean when we create a script for example #! / bin / bash
echo "I make it up" and we wait for the output of the echo to do something with it. example echo "I make it up" if [[$? -gt 0]] then do something with the output of echo
The echo execution response is obtained through stdout in the tty terminal but from crontab "there is no tty" and a crash occurs and crontab does not execute the application. This is solved with nohup. More information man nohup