Using command line to open, edit and save content in file - json

During the work, there are a lot of partners in the project, and sometimes I need to switch among different partners a lot, and every time the process:
change the partner name in .env file manually
run docker-compose down in the terminal
run docker-compose up -d in the terminal
run gulp dev --partner <partner name> in the terminal
So my question is :
Would it possible to use one line of command to complete the entire above process (such as in the package.json, "docker": "docker-compose down && docker-compose up -d", then npm run docker means running docker down and up)
Basically the main point should be :
Would it be possible to use command line to open, edit and save a file? (I know I could use command line to open vi, and then to edit inside vi, but here is not the case)

There's certainly methods of text editing from the command line (see sed/awk etc.) My solution to this, would be to have multiple .env files:
e.g. .env.alice; .env.bob; .env.charlie
Then as part of my script I would symbolically link the one I wanted:
ln -sf .env.alice .env
The rest as you described.

Related

How to create opt/bitnami/apps/myapp/conf/httpd-prefix.conf and include /opt/bitnami/apps/myapp/conf/httpd-app.conf

Please guys help out, am using google compute engine for the first time and using bitnami. I have successfully spin up a server, and connected with ssh but am stock here https://docs.bitnami.com/virtual-machine/components/nodejs/#how-to-create-a-custom-nodejs-application
Can anyone help me explain how:
1.- Create and edit the /opt/bitnami/apps/myapp/conf/httpd-prefix.conf file and add the line below to it:
Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
2.- Create and edit the /opt/bitnami/apps/myapp/conf/httpd-app.conf file and add the content below to it. This is the main configuration file for your application, so modify it further depending on your application's requirements.
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
NOTE: 3000 is the default port for the Express server. If you have
customized your application to use a different port, change it here as
well.
3.- Once you have created the files and directories above, add the following line to the end of the main Apache configuration file at /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf, as shown below:
Include "/opt/bitnami/apps/myapp/conf/httpd-prefix.conf"
According to the Bitnami guide shared by you, you should follow the following steps (I added more detailed information):
1.- Create directories
For that, you should run the following commands:
sudo mkdir -p /opt/bitnami/apps/myapp
sudo mkdir /opt/bitnami/apps/myapp/conf
sudo mkdir /opt/bitnami/apps/myapp/htdocs
2.- Create two files
For that, you can run the following commands:
touch /opt/bitnami/apps/myapp/conf/httpd-prefix.conf
touch /opt/bitnami/apps/myapp/conf/httpd-app.conf
3.- Add content to the first file
You can edit the file using any text editor, for example nano
nano /opt/bitnami/apps/myapp/conf/httpd-prefix.conf
The above command opens the text editor, you should copy/paste or write the following line:
Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
Close the editor using Ctrl+X(you will be prompted to save your file if you have not)
4.- Add content to the second file
You can edit the file using any text editor, for example nano
nano /opt/bitnami/apps/myapp/conf/httpd-app.conf
The above command opens the text editor, you should copy/paste or write the following line:
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
Close the editor using Ctrl+X(you will be prompted to save your file if you have not)
5.- Edit Apache config file
Once you have created the files and directories above, add the following line to the end of the main Apache configuration file. Open the file (again using nano):
nano /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf
The above command opens the text editor, you should copy/paste or write the following line:
Include "/opt/bitnami/apps/myapp/conf/httpd-prefix.conf"
Close the editor using Ctrl+X(you will be prompted to save your file if you have not)
6.- Restart apache
For that execute
sudo /opt/bitnami/ctlscript.sh restart apache
7.- Start the Express server
cd /opt/bitnami/apps/myapp/htdocs
./bin/www
Alternatively, use the following command to start the server and keep it running even after your server session ends. Replace FILE with the correct filename for your application.
forever start FILE.js

PHP Mysql laravel 5.4 terminal issue

i am new to laravel i just figured out how to install composer laravel etc etc on my local machine MAMP on windows , Now i am confuse with the command on terminal which is
C:\project>mysql -uroot -proot
'mysql' is not recognized as an internal or external command,
operable program or batch file.
How can i fix this ?
setting Environment will solve the issue
Go to Control Panel -> System -> Advanced
Click - Environment Variables
Go to- System Variables find PATH and click on it.
add the path to your mysql\bin folder to the end paths. (ex: E:\xampp\mysql\bin) and add ; end of the line
Close all the command prompts you opens.
Re open and try it.
Setting the PATH to point to the MYSQL bin folder is normally the first thought, but I find that dangerous as things get left lying around when you change software.
I normally create a little batch file in the projects folder or in a folder that it already on your PATH, like this
mysqlpath.cmd
echo off
PATH=C:\mamp\path\to\the\mysql\bin;%PATH%
mysql -v
The mysql -v will output the mysql version number but it is a handy way of knowing that the correct folder has been added to the PATH. This adds the folder to the PATH but only for the life of the command window.
Then just run this from any command window when you want to use MYSQL from the command line
> phppath
You may also like to create one for PHP as well
phppath.cmd
echo off
PATH=C:\mamp\path\to\the\php\;%PATH%
php -v

Create Dockerfile interactive?

If you look at dockerfiles the often contains lines like this:
sed 's/main$/main universe/' -i /etc/apt/sources.list
I think it is difficult to set up things like this.
Is it possible to launch a default OS image, then enter it interactive with a shell, do some modifications, and then print out the diff (filesystem diff)?
The diff should be used as the dockerfile to recreating the image.
But maybe I am missing something, since I am new to docker.
You can create docker images several ways.
I tend to have two windows open when I create a new docker image. One for my docker run -i -t centos bash, where I am writing all my commands to get it the way I want, and the other one with the Dockerfile, so I can put in whatever I do.
When it comes to config files, I am putting them in the files/folders that matches the one on the image.
Example, if I change /etc/something/file.conf, I will create the file in etc/something/file.conf in the same directory as my Dockerfile, and then use Dockers ADD command to add it whenever I do a build.
This works perfectly, since I can have all this in a git repository with a README.md containing the info I need for running/building the image.
The other thing you can do is to is to run docker ps -a after you are done with the changes you wanted to create an image on, and get the docker ID of the image of the container you just configured. You can tag this new image, or start it with docker run abc0123 bash just like you would a normal docker image.
The problem with this is that you wont be able to easily build it next time without bringing the whole image.
Dockerfiles with ADD is the way to go!
If you do not want to run sed (which is used to preserve the default file and of minimal changes to it), you can simply ADD the modifies file.
For that you can docker run -it --rm thebaseimage /bin/sh (or any other shell that is provided) and edit it in place. Then just copy it outside the container (or docker export it) and use it on your build.
The downside of ADD vs RUN sed… is that, if something changes in a new version of your base image, you will overwrite those changes.
The Dockerfile is (mostly) equivalent to a series of docker run and docker commit commands. You wouldn't want to look at the docker diff to see what files changed -- you'd want to see what docker run commands had occurred. You could get these from your host shell history and process these into a Dockerfile.

cron tab to execute rails commands

i am running a cron tab for every 5 minutes,it contains an .sh files which need to be executed ,where that .sh file consists of ruby code....one thing i can't understand that when i am executing the .sh file directly in terminal its get execute,but the same thing in crontab fails..my entry in crontab follows :
1) mysqldump -uroot -p'myPassword' redmine144 > redmine144_$(date +%Y_%m_%d_%H_%M).sql;
2) cd /home/ror/Projects/redmine144/;
source /usr/local/rvm/environments/ruby-1.9.3-p194#redmine144
bundle exec rake "hb:project_progress"
First one to take backup and it is working fine.
Second one to run some ruby rake task(not working form cron tab)
usually crontab output in not directed to stdout so you check your out put in /var/log/cron file which contains the cron logs. you can add the output and redirect the error, for more see http://www.thegeekstuff.com/2012/07/crontab-log/ and check what error pops upp and you'll be able to figure it out...
Making RVM work with cron is really tricky. I'll share a snippet from my own crontab that is proven to work (with system-wide RVM) - just make sure your app path has a .rvmrc specifying the ruby version and gemset.
MAILTO=mymail#gmail.com
SHELL=/bin/bash
? ? ? ? ? source /etc/profile.d/rvm.sh; cd /app/home/path && bundle exec rake whatever_you_need RAILS_ENV=production
SHELL is important.
The MAILTO is there to aid debugging and could be removed later.
Don't forget to substitute your schedule for the question marks.

How to install MySQL on Leopard, Mac OS X 10.5?

I followed this tutorial to the very end, then found out it didn't work right. I think I have everything installed but when I type
mysql -uroot
I only get
-bash: mysql: command not found
Note: I did not skip the "Setting the Path" step. Upon running this command for the first time:
mate ~/.bash_login
This brought up an empty file. So I added this line:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
I saved the file, closed TextMate, executed the following command:
. ~/.bash_login
...and continued with the tutorial. Based on your suggestions, I thought maybe the file didn't actually get saved. So I ran the following command to bring up the file again:
mate ~/.bash_login
...yet the contents of the file were as they should be.
Any suggestions?
You probably don't have the mysql binaries in your path.
The link you posted has a section on setting the path, titled "Setting the Path Do not skip this step! Most everything else will fail if you do."
EDIT: As debugging steps, try:
First launching a new terminal window. Does it run now?
Typing "echo $PATH" at the prompt. Does the path show up correctly as you've typed it in bash_profile?
Running it the long way: /usr/local/mysql/bin/mysql -u root
Does the application run?
Did you follow the step that says
Setting the Path
Do not skip this step! Most everything
else will fail if you do.
Did you close your terminal window and re-open it afterwards?
Update:
What does "which mysql" say? Does "ls /usr/local/mysql/bin" say?
Two things:
Try editing ~/.profile (rather than ~/.bash_profile or ~/.bash_login).
You may find it easier to use the native Mac style .dmg installer directly from Sun.
One nice thing about the dmg installer is that it automagically sets up symlinks to /usr/local/mysql (which means less - or no - fiddling with your $PATH).
Another option would be to use MAMP.
It has Apache, PHP and MySQL packaged with no further setup necessary.
MySQL is usually put in /usr/local/mysql/bin/
You need to add this to your PATH, you can do this by adding the follwoing lines to your .bash_profile
PATH=$PATH:/usr/local/mysql/bin/
export PATH
The .bash_profile file is located in the root of your username directory.
Make sure you restart your Terminal for the setting to take affect.
And if you're not a command-line person, I highly recommend you also install the MySQL Preference Pane to start/stop the server and install Sequel Pro to create databases and run queries.
ftp://ftp.mysql.com/pub/mysql/download/gui-tools/MySQL.prefPane-leopardfix.zip
http://www.sequelpro.com/