BASH - If $TIME between 8am and 1pm do.., esle do.. Specifying time
variables and if statements in BASH
I need to run a command when something is entered in BASH with a certain
time-frame, and if it's not that time run another command. Here's what
I've got so far, but it doesn't appear to be working..
FLATTIME=$(date "+%H%M")
FLATTIME=${FLATTIME##0}
if ! [[ $FLATTIME -gt 1130 ]] ; then
mysql --host=192.168.0.100 --user=myself --password=mypass thedb << EOF
INSERT INTO $STAFFID values
('','$STAFFID','$THETIME','','$THEDATE','$DAYOFWEEK');
EOF
else
mysql --host=192.168.1.92 --user=myself --password=mypass thedb << EOF
UPDATE $STAFFID SET Out_Time='$THETIME' WHERE date='$THEDATE';
EOF
fi
Ideally what I'd like is to have something like: if the time is between
8am and 1pm do the first command, if the time is between 1pm and 11pm do
the second command, else echo "someone's been at work too long". I've
tried a few variations but no luck, it just seems to run the first command
whatever I do..
No comments:
Post a Comment