Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-11-2012 #1Just Joined!
- Join Date
- May 2012
- Posts
- 82
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
I noticed that the process execution sequence is not as expectedCode:while read line do 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 i=$((i+1)) done < $url_list
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?
thanks!
- 10-11-2012 #2Just Joined!
- Join Date
- May 2012
- Posts
- 43
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.
Source: BashSheet - Greg's WikiAmpersands 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.


Reply With Quote
