pvsbandi
asked on
Linux scripting to consolidate separate files
Hi,
We get some postgres db command files (Insert, Update, Create, Drop etc) with the DB commands in them on a location(\usr\DB Scripts) in our Linux environment.
We need to come up with a script, which when ran,
-> creates a consolidated file, with the statements in each file, ended with a GO statement
-> Move the individual files used in the above consolidated file, into an archive directory, with timestamp in the name.
-> Leave any unused files in the original location (\usr\DB Scripts); These will be the files which may have been added just after the script was run
-> Run another script which compiles the consolidated file, against the database.
Can someone kindly help with this? I'm fairly new to the linux world.
We get some postgres db command files (Insert, Update, Create, Drop etc) with the DB commands in them on a location(\usr\DB Scripts) in our Linux environment.
We need to come up with a script, which when ran,
-> creates a consolidated file, with the statements in each file, ended with a GO statement
-> Move the individual files used in the above consolidated file, into an archive directory, with timestamp in the name.
-> Leave any unused files in the original location (\usr\DB Scripts); These will be the files which may have been added just after the script was run
-> Run another script which compiles the consolidated file, against the database.
Can someone kindly help with this? I'm fairly new to the linux world.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi noci,
> "Except that i wanted to keep it as simple as possible... and not pull too many tricks in the equation."
OK, but it's debatable whether this:
(echo "" ; echo "GO;" ) >> t/sqlscript.sql
is more simple than this:
echo -e "\nGO;" >>t/sqlscript.sql
I find the later simpler...and more concise. But I accept that others may have different opinions.
> "Except that i wanted to keep it as simple as possible... and not pull too many tricks in the equation."
OK, but it's debatable whether this:
(echo "" ; echo "GO;" ) >> t/sqlscript.sql
is more simple than this:
echo -e "\nGO;" >>t/sqlscript.sql
I find the later simpler...and more concise. But I accept that others may have different opinions.
ASKER
Thank you, both!
Except that i wanted to keep it as simple as possible... and not pull too many tricks in the equation.
For the trailing go an empty line feed either echo "" or echo -e "\n" is needed because not all files end with a linefeed before end-of-file.
Also not mentioned before is that the asker should put his own activation script where RUNSCRIPT is mentioned here.