DEV Community 👩‍💻👨‍💻

mostafalaravel
mostafalaravel

Posted on

how to resume multiple commands on one command

Hello ,

I need every time when I pull from the repository to run these commands :

sudo git pull origin
php artisan migrate
sudo npm update
sudo npm run prod

How to put all the commands above in one command (alias) ? like: update-project.

Thanks

Top comments (13)

Collapse
 
qm3ster profile image
Mihail Malo

Since you clearly have npm and this is happening in a directory with a package.json, I recommend familiarizing yourself with npm-run-all(run-s, run-p), or equivalent, then you won't be tied to bash (can run on windows without bash installed, for example).

Also, there's pretty much no reason any of these commands should require sudo, and especially the npm ones are wildly unsafe. update can run arbitrary installation lifecycle scripts from unknown parties, and run well... runs the actual code of the dependencies in accordance with how your scripts call it. If this doesn't work without sudo in your case, you should probably fix the file permissions instead of giving superuser access to these already insecure tools.

Finally, you said "every time when I pull from the repository". These is a small chance you might be interested in git hooks, eg through git-hooks-js or husky

Collapse
 
moopet profile image
Ben Sinclair

It's also very unlikely you want to run git pull every time you pull, because that would never end...

Collapse
 
qm3ster profile image
Mihail Malo

lmao

Collapse
 
mostafalaravel profile image
mostafalaravel

Thanks Mihail Malo

Collapse
 
mostafalaravel profile image
mostafalaravel

when I run npm update I got this error :


npm ERR! code EACCES
npm ERR! syscall unlink
npm ERR! path /home/helloworld/.npm/_logs/2020-11-25T10_30_33_060Z-debug.log
npm ERR! errno -13
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 1001:1001 "/home/mabdellaoui/.npm"
npm ERR! code EACCES
npm ERR! syscall open
npm ERR! path /home/mabdellaoui/.npm/_cacache/tmp/7beab320
npm ERR! errno -13

Enter fullscreen mode Exit fullscreen mode


`

Thread Thread
 
qm3ster profile image
Mihail Malo

Wow, what an amazing error!
Good job, npm developers!
It tells you WHY this happened, and also tells you the correct way to fix it!

Collapse
 
fausrguez profile image
Faus Rodriguez • Edited on

I would recommend you to use a Makefile
The syntax's quite simple.

command_name:
    command_1
    command_2
    ...
Enter fullscreen mode Exit fullscreen mode

here is an example:

update_and_compile_prod:
    sudo git pull origin
    php artisan migrate
    sudo npm update
    sudo npm run prod
Enter fullscreen mode Exit fullscreen mode

After you only need to call make update_and_compile_prod (make command_name), and it will run smoothly :)

Also, you can add this command to the script list on your package.json and run it with npm.

You can also try to investigate if you can use a githook to trigger that action every time you pull

Collapse
 
mostafalaravel profile image
mostafalaravel

Thanks

Collapse
 
_garybell profile image
Gary Bell

Have you considered putting the commands in a single shell script? That way if you need to add more steps, you do it in one place.

It also means if you gave to migrate to a new server or development machine, you know exactly what you need to run. You don't have to rely on memory of what is and is not part of an alias.

Collapse
 
mostafalaravel profile image
mostafalaravel

Thanks for this answer, do you have any idea how could be this shell script ?
Thanks

Collapse
 
zaffja profile image
Zafri Zulkipli

Something like this in your .bash_aliases will do if I understand your question correctly.

alias update-project="git pull && php artisan migrate && npm update && npm run prod"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mostafalaravel profile image
mostafalaravel

Thanks Zafri

Collapse
 
msamgan profile image
Mohammed Samgan Khan

create a deploy.sh in your root with the following content.

this is how you can so this.

codebysamgan.com/creating-a-deploy...

Tired of sifting through your feed?

Find the content you want to see.

Change your feed algorithm by adjusting your experience level and give weights to the tags you follow.