I need your help as I am having a hard time configuring out how to:
-
store the generated sql file (ex. filename: USERLIST_052024 -> current month and year) into specific folder
-
zip the file (generated in bullet 1)
-
and place into ftp using shell script.
Every 1st day of the month, we need to generate the list of users in our database. I already have my sql script to generate the user list (filename: USERLIST_<MMYYYY>, for this month it should be USERLIST_052024). The sql script located in this folder /home/export/project/users/.
I need to create a script that will auto generate the file, zip it and put into sft. Basically, I only know how to do it manually but I’m not sure how to put all the codes in 1 script.
My script is something like this:
#!/bin/bash
sqlplus root/[email protected]:5001/abyg @/home/export/project/users/USER_LIST.sql << EOF
quit
EOF
7z a USERLIST_052024.zip USERLIST_052024.txt -pabcd1234
This is working and it can generate the file and zip already however:
-
How do I store the generated file into specific folder?
-
How do I find the file with filename contains ‘_MMYYYY’ current month and year (ex. _052024) and zip it? My command in my shell script to zip the file is only straightforward. The name of the zip file should not be hardcoded since every month the USERLIST_<MMYYYY> will be changed.
-
How do I insert this command to put into sftp:
ftp 10.43.234.17
username: root
password: ftppass
directory: /sftp/home
in my script?
Thanks in advance.