1

In windows i just do this.

@echo off
for /L %%n in (1,1,10) do start "" "C:\Program Files\Mozilla Firefox\firefox.exe" -P user%%n -no-remote imacros://run/?m=we.js ping 192.168.1.1 -n 1 -w 1500 > NUL

There is some equivalent in ubuntu to run different profiles the path of my firefox is, /opt/firefox/firefox and need make a loop to select the diferent users.

IMPORTANT. I need to run all my profiles at the same time.

The other question is. Where is the path of my profiles in firefox in ubuntu. In windows is just simple in the appdata but in ubuntu seems more complicated. someone can say me where is the path of my profiles?

2 Answers2

2

I don't grok batch, but guessing at the meaning the bash equivalent would look like:

for n in {1..10}
do
    /opt/firefox/firefox -P user$n -no-remote imacros://run/?m=we.js ping 192.168.1.1 -n 1 -w 1500 &> /dev/null &
done
  • {n..m} is the sequence form of brace expansion in bash. You could also use a C-style for loop:

    for ((n = 1; n <= 10; n++))
    do
    ...
    done
    
  • $n is how you get the value of variable n.

  • &> /dev/null redirects both error and normal output to the /dev/null special device, effectively discarding them
  • the & by itself sends the command to the background, so the script no longer waits for the command to finish before continuing to the next command.

Your Firefox profiles are likely in ~/.mozilla/firefox/.


(Is that ping really part of Firefox's arguments?)

Olorin
  • 3,488
  • But in the for how will be like in C style? And the extension of file is bash sh or other? – Sergio Ramos Jun 29 '18 at 01:58
  • @SergioRamos like in the second code block for ((n = 1; n <= 10; n++)), the rest of the code remains the same. The extension is up to you: https://askubuntu.com/q/803434/760903 – Olorin Jun 29 '18 at 02:02
  • I just have one small problem when i run the script only open one profile (doesnt open all at the same time). once time i close the first profile of my firefox open the second profile, i mean that not open all profiles in once time. Its not possible to open all at the same time? – Sergio Ramos Jun 29 '18 at 02:27
  • 1
    You may need to background each instance, by adding & to the end of the command (otherwise the shell loop will wait for each instance to close before continuing). – steeldriver Jun 29 '18 at 02:44
  • @sergio yes, it's possible. See steeldriver's comment and my updated answer. – Olorin Jun 29 '18 at 03:27
2

The default Unix shell does not give you a one to one equivalent for all the features you're using. Here are what you can do with the basic shell:

Trace

@echo off

By default a shell script is silent, so it is "off" by default. The flag to turn on trace is -x (set -x).

Loop 1 to 10

for /L %%n in (1,1,10)

This can be done in a Unix shell script using a variable and a while. Newer shells, such as bash, offer ways to write such, but if you want to write a script that works on (nearly) all Unix machines, then you want to stick to the basic features:

#!/bin/sh
n=1
while test $n -le 10
do
  ...
  n=`expr $n + 1`
done

The ... is the script to be executed 10 times. The expr command is used to increment the counter by one on each iteration. Notice the spaces, they are important (not the indentation, although I would suggest you keep the indentation proper).

As @Olorin mentioned, the expr command can also be replaced by:

n=$(($n + 1))

Start Firefox as a background process

start "" "C:\Program Files\Mozilla Firefox\firefox.exe" &
                    -P user%%n -no-remote imacros://run/?m=we.js

(I broke the line, in DOS script that requires an & at the end of the line).

Here you start a program using "start" which means it goes in the background. And you specify parameters, one of which uses that counter n. Assuming firefox is in your path (it will if you installed the default version) then you do not need a full path, just the following:

firefox -P user$n -no-remote imacros://run/?m=we.js &

This is an sh script where the ending & is used to start that process in the background. That means the command is started and the shell returns immediately.

You also have a special variable set that gives you the PID of the new process. This could be useful later if you want to send a signal or just know whether the process is still running or not. (i.e. FIREFOX_PID=$!--in your case, though, you're going to start 10 of them... just one such variable would not work for you.)

Send one quiet ping with a 1.5s timeout

ping 192.168.1.1 -n 1 -w 1500 > NUL

This ping looks like a separate line of code. The -n 1 is to repeat one time and the -w 1500 to specify the timeout. The -w is one to one equivalent on Linux. The -n (number), however, has to be replace by -c (count). Finally, the NUL special file can be replaced by /dev/null.

ping 192.168.1.1 -c 1 -w 1500 > /dev/null

Note: to make ping quiet, you can also use -q as in:

ping 192.168.1.1 -q -c 1 -w 1500

Of course, if the ping is part of the Firefox command line (unlikely) then you probably shouldn't transform it at all.

Alexis Wilke
  • 2,707