I need to configure some value from cron tab and get those into my shell script file. I am explaining my script file below.
#!/bin/sh
#=====================================================================
# Set the following variables as per your requirement
#=====================================================================
# Database Name to backup
MONGO_DATABASE="ubot-db"
# Database host name
MONGO_HOST="127.0.0.1"
# Database port
MONGO_PORT="27017"
# Backup directory
BACKUPS_DIR="/home/subhrajp/UBOT/"
# Database user name
DBUSERNAME="username"
# Database password
DBPASSWORD="passw0rd"
# Authentication database name
DBAUTHDB="admin"
# Days to keep the backup
DAYSTORETAINBACKUP="14"
#=====================================================================
TIMESTAMP=$(date +'%Y_%m_%d_%H-%M-%S')
BACKUP_NAME="mongobackup_$TIMESTAMP"
echo "Performing backup of $MONGO_DATABASE"
echo "--------------------------------------------"
# Create dump
mongodump --host $MONGO_HOST -d $MONGO_DATABASE --port $MONGO_PORT --out "${BACKUPS_DIR}${BACKUP_NAME}"
echo "--------------------------------------------"
echo "Database backup complete!"
In this file I have hardcoded the BACKUPS_DIR
value but I need to configure from crontab as I am running this file as cron job. My crontab setting is given below.
* * * * * /home/subhrajp/UBOT/git/uBot-Hosting/container/app/mean-stack/node-js/utils/backup-mongodb.sh
Here My requirement is I need to configure some values as environment variable from crontab and fetch those values inside my shell script which is given above.