Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
and I guess save this as .sh file right? –  Gabriele Cripezzi Jun 5 '13 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. –  grawity Jun 5 '13 at 19:24
    
@GabrieleCripezzi you just open a terminal, copy paste the command and hit enter. –  terdon Jun 5 '13 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 Cripezzi Jun 5 '13 at 19:46
    
@GabrieleCripezzi its safe, it wont harm your machine but it will stop the process obviously. –  terdon Jun 5 '13 at 19:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.