sed to change text in existing files and Nano to create new files.
I change text with
sed this way, for example:
sudo sed -i 's/TESTING === "1"/TESTING === "0"/g' /etc/csf/csf.conf
Is there a way to create files with it, without going inside Nano or VI and pasting text, giving permission and then execute?
Usually I do
cd ~ && nano script.sh && chmod +x script.sh && ./script.sh && rm -rf script.sh and then I paste all the script content inside, then save and execute.
This time however, I want to automate even that, and just paste everything as one input and run it in place.
In other words, I look for either a way to run the script from paste, or to paste it into a temporary file and run it "in-place" the moment I close the file and by that, to run it with the least number of clicks and pastings.
Why I need this solution:
The process can be repetitive when working with several server environments and I want to save time when doing this task time and again.
The discussion about the legitimacy of such action is surly a discussion by itself...
Here is an example --- I paste the following coomand to prompt (the first one, that includes ampersands), go into Nano to create the script and right then, I paste the following script syntax, save, and it it is being executed. I wish to automate this process as to do all of this, in one pasting / one action.
cd /home/testo && sudo nano script.sh && sudo chmod +x scripts.sh && sudo ./script.sh #!/bin/bash -x # Basic update and upgrade: sudo apt-get update -y sudo apt-get upgrade -y # Setup CSF-LFD: sudo rm -f csf.tgz sudo wget https://download.configserver.com/csf.tgz sudo tar -xzf csf.tgz sudo sh install.sh sudo perl /etc/csf/csftest.pl sudo sed -i 's/TESTING === "1"/TESTING === "0"/g' /etc/csf/csf.conf sudo csf -r