Running multiple commands with su in Bash
This command runs fine:
su root -c "date; ls -lh"
But in this command:
su root -c "tcpdump -i wlan0 -s 1500 -w CCCCCC & ; ls -lh;"
Since you have &
before ;
therefore you are getting errors. Try removing &
and re-executing the command.
Or you can run your command like this:
su root -c "(tcpdump -i wlan0 -s 1500 -w CCCCCC &); ls -lh"
As anubhava says, your
su root -c "tcpdump -i wlan0 -s 1500 -w CCCCCC & ; ls -lh;"
command is failing because you’re not allowed to have
&
followed immediately by ;
.
You can see this just by typing the commands directly into the shell:
true & true
workstrue & ; true
doesn’t work
If you want the tcpdump
command to run in the background,
remove the ;
, as in
su root -c "tcpdump -i wlan0 -s 1500 -w CCCCCC & ls -lh;"
(and you don't need the ;
at the end, either, but it doesn’t hurt).