Got your PM ... 3 day turn around on this!!! Think you need to share here what you shared via PM to me as that was more descriptive than this posting.
From what you described in the PM, think I'd look into installing moosh which is a command line only utility for Moodle. It has several commands.
The second link will show various commands that might be able to put into a bash shell script to do what you want.
'spirit of sharing', Ken