0

What kind of script I need to run a batch on Linux?

I have to launch this line

php magmi.cli.php -profile=FINALE -mode=create -CSV:filename="path/to/file01.csv"

40 times for 40 different CSV files unless I have a script to exectute them all in a batch style.

thanks!

1 Answer 1

0

You can use a simple shell script. To run your command 40 times, do:

for file in path/to/*.csv; do 
      php magmi.cli.php -profile=FINALE -mode=create -CSV:filename="$file";
done

The construct for VARIABLE in PATH; do SOMETHING; done goes through every file (or and folder) sequentially, assigning VARIABLE to each file/folder name in turn. It then runs whatever SOMETHING is once for each file. You can then refer to the file using $VARIABLE, for example, in the script above, VARIABLE is file and I pass it to php as $file.

8
  • and I guess save this as .sh file right?
    – Gabriele
    Jun 5, 2013 at 19:06
  • @GabrieleCripezzi The extension is irrelevant. You tell the OS it's a sh script by either running it as sh yourscript or by adding a #!/bin/sh line at the top of the file... Alternatively, just paste the whole command into the terminal. Jun 5, 2013 at 19:24
  • @GabrieleCripezzi you just open a terminal, copy paste the command and hit enter.
    – terdon
    Jun 5, 2013 at 19:26
  • ok it's done. created a import.sh file into /scripts and executed (no #!/bin/sh att he beginning of he file because vim didn't allow me to. I chose the file solution vs the ssh cli as it seems more reliable in case of loss of internet connection here. By the way... is it safe to shut thePC down now that the batch has been launched or do I have to keep it on? Thanks to the both of you!
    – Gabriele
    Jun 5, 2013 at 19:46
  • @GabrieleCripezzi its safe, it wont harm your machine but it will stop the process obviously.
    – terdon
    Jun 5, 2013 at 19:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .