0

I need to check the printed logs inside my cron file in ubuntu/cent os server. I am explaining my code below.

backup-mongodb.sh

#!/bin/bash

name = "uBot_sandbox"
export DATABASE_NAME="planets"
export BACKUP_LOCATION="/home/UBOT"


for container_name in $(docker ps  --filter="name=$name" -q);do
    echo "container name : $container_name"

done

I set this file using crontab -e like below.

* * * * * /bin/bash  /home/subhrajp/UBOT/git/uBot/python3.7-alpine3.8/app/mean-stack/node-js/utils/backup-mongodb.sh

Here I need to check the echo output of that .sh file once the cronjob started. Also I need to know what is the command to run the cron file manually without starting the cronjob so that I can use it while developing. Please help me to resolve my problem.

subhra_user
  • 439
  • 5
  • 19
  • The output from `cron` goes to your email inbox. If you want to avoid that, have it log to a file, like `bash whatever >>filename 2>&1` (this creates a file `filename` in your home directory; specify a path to a location where you have write access if you want it somewhere else). – tripleee Feb 09 '21 at 07:28
  • Your `cron` job is already running once per minute; just capture what it does instead of running it manually _in addition_ to this. There is no simple way to ensure that you get _exactly_ the same environment on the command line, though if you know what resources your script uses, it's not hard to have a `cron` job simply print their status to a file which you can then use to recreate the same environment. ... – tripleee Feb 09 '21 at 07:31
  • ... Basically, the environment will be a lot more constrained (this is easy enough to simulate; just unset all the variables which don't exist in the `cron` job, and override the ones which get different values, such as `PATH`) and there will be no TTY for I/O. – tripleee Feb 09 '21 at 07:31
  • All of these are common FAQs about `cron` jobs so I'll suggest this as a duplicate of our canonical for that. – tripleee Feb 09 '21 at 07:31
  • Does this answer your question? [CronJob not running](https://stackoverflow.com/questions/22743548/cronjob-not-running) – tripleee Feb 09 '21 at 07:31

0 Answers0