Thursday, January 19, 2017

Shell script: How to loop through directory

Hi

Today we will learn, how to loop through directory or folder with shell script.

Some days ago, working on a project, we have a requirement where we have to change the origin of a app directory. Because we have shifted our git repository to another server. There were 500 apps. So changing manually for each directory, it was time consuming.

What we do then, made a shell script for looping through each directory and excute a command to change origin.

First I made a origin.sh file in root folder and put the below script in that file.

 #!/bin/bash  
 for f in /home/username/your_directory_path/apps/*;  
  do   
    [ -d $f ] && cd "$f" && git remote set-url origin your_new_origin_url  
  done;  

And now run the file with below command in terminal

 sh ./origin.sh  


By running this command, it will excute the command written in origin.sh file.
It will loop through each directory of given path and excute the command.

Thanks

Sunday, January 8, 2017

Laravel migration : Resetting and Re-running all

Hi

Today we will learn how to resetting migration and re-running in laravel.

To reset migration we use command

 php artisan migrate:reset  

and to run migration we use command

 php artisan migrate  


But running above 2 command, we can do it by 1 command.

 php artisan migrate:refresh  

By running above command, it will reset and and run all the migration again.

Thanks