Linux environmental variable for bash scripts

Viewed 53

I am trying to create some bash scripts to do an export of new email accounts made in the last 24 hours. It uses GAM (google apps manager) to get the accounts created in the last 24 hours with a filter for the account creation time. To accomplish this, I want to make an environmental variable that has today's date formatted the way that the G Suite API formats it. The script I made (date.sh)to create the date variable looks like this

#!/bin/bash
export todayDate=$(date +'%Y-%m-%dT%H:%M:%S.000Z')
echo $todayDate

I would like this to run right after midnight with a cron job to get the day's date set. This seems to work. The issue I am having is that when I run my next script

#!/bin/bash
source /home/user/date.sh
export GAM_CSV_ROW_FILTER="creationTime:time>=$todayDate"
/home/user/bin/gam/gam print users query orgunitpath="'/Staff Accounts'" externalid organization firstname lastname phone creationtime > /home/user/accounts.csv

It seems to reset the variable to the time that the second script was run. For example, if I have cron run the first script at 00:00:00, and the second script at 06:00:00, the variable seems to be 06:00:00 at the time that the second script runs, as opposed to 00:00:00 which I would like it to be.

Perhaps I've over complicated this, ideally I would just have it export the variables and not have to use

source /home/user/date.sh

but I can't seem to figure out a way to pass the variables to bash since the scripts are a subprocess.

Hopefully this makes sense, I'm fairly new to bash scripting and Linux so any help would be appreciated.

0 Answers
Related