Change strings in multiple shell scripts
6:55 PM
There are many scripts in place on database servers and many send
email for exit status, alerting etc. The mail list, i.e recipients,
often includes a customer alias as well as Dimension Data staff lists
etc. There are times when one may want to change a recipient, or in fact
any string that occurs regularly in scripts.
Sed is used to edit one or many files and is a powerful tool. Rather than edit each script to change a string you can run a single command.
Scenario
Xactly has added our Oracle cron alias as a recipient to a large majority of their own monitoring scripts on their database servers. For the most part these mails are of no interest to us, as they are not from jobs that we manage. The scripts in question are named *.sh or *.bash for example and alias we needed to remove was "corp-dba-oracle-cron@alert.opsource.net".
Before the change the string looks like
We need to remove our alias from the definition of the mail recipients, and we use sed for this.
sed -i "s/ corp-dba-oracle-cron@alert.opsource.net//g" *sh
This updates all files in place, i.e. no redirection to a new filename, and the string now looks like this
This will only apply to all files named "*.sh" in the current directory. It is not recursive.
Sed is used to edit one or many files and is a powerful tool. Rather than edit each script to change a string you can run a single command.
Scenario
Xactly has added our Oracle cron alias as a recipient to a large majority of their own monitoring scripts on their database servers. For the most part these mails are of no interest to us, as they are not from jobs that we manage. The scripts in question are named *.sh or *.bash for example and alias we needed to remove was "corp-dba-oracle-cron@alert.opsource.net".
Before the change the string looks like
FAILMAILLIST= "ops@xactlycorp.com corp-dba-oracle-cron@alert.opsource.net" |
sed -i "s/ corp-dba-oracle-cron@alert.opsource.net//g" *sh
This updates all files in place, i.e. no redirection to a new filename, and the string now looks like this
FAILMAILLIST= "ops@xactlycorp.com" |
0 comments