Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    using two users in a script and the synchronization issues

    the following is a script snippet in my script
    I run this script using root, coz tcpdump need root priviledge
    but I need to use "sudo -u regular_user" to run firefox

    while read line
      sudo -u regular_user App/Firefox/firefox --profile Data/profile &
      sleep 2
      cd ${capture_dir}
      tcpdump -i eth0 -w capture${i}.pcap &
      cd ${firefox_dir}
      sudo -u regular_user App/Firefox/firefox --profile Data/profile -new-tab case.html
      sleep 200
      pid_firefox=`ps -ef|grep "firefox"|grep -v "grep"|awk '{print $2}'`
      kill -9 $pid_firefox
      sleep 15
      pid_tcpdump=`ps -ef|grep "tcpdump"|grep -v "grep"|awk '{print $2}'`
      kill -9 $pid_tcpdump
      sleep 3
    done < $url_list
    I noticed that the process execution sequence is not as expected
    sometimes firefox processes are not all killed and then the next loop has already started, can anyone tell me are there any process synchronization issues in my script?

  2. #2
    You can use && or || to tell a command to run once the previous command was successful or failed.

    By using a single ampersand, you're telling bash to run that process in the background and begin the next immediately.
    Ampersands separate asynchronous commands. An ampersand does the same thing as a semicolon or newline in that it separates commands, but it causes Bash to execute the first command asynchronously, which means that Bash will run it in the background and run the next command immediately after, before waiting for the former to end.
    Source: BashSheet - Greg's Wiki

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts