Avoiding "file collision"


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Avoiding "file collision"
# 1  
Old 01-29-2010
Avoiding "file collision"

I don't know if there's a better name for what I call "file collision"... Basically, I have a script that I'm using for quick and dirty MySQL testing. Here's the idea...


Code:
#!/usr/local/bin/bash

for num in `jot $1`  ##  Yep, jot... this is FreeBSD
do
/usr/bin/time mysql --user=root --password=password -e "USE test ; SELECT quote FROM table ORDER BY RAND() LIMIT 1;" > /dev/null &
sleep $2
done

Now, what I'd really like to do is add these time parameters:

Code:
/usr/bin/time -a -o /tmp/mysql_times ...

However, this seems to sometimes result in weird output, such as:

Code:
...snippet...
        3.38 real         0.00 user         0.02 sys
        3.38 real         0.00 user         0.00 sys
        3.34 real         3.35 real         0.01 user         0.00 sys
        0.00 user         0.00 sys
        3.42 real         0.00 user         0.01 sys

It appears that multiple writes are "colliding", resulting in mixed-up data. Any suggestions on the best way to handle this? Many thanks.
# 2  
Old 01-30-2010
You could e.g. have each process write to its own temporary file and then combine these files in the end. About your script. Why do you use a sleep statement after you put a process in the background and why is there no wait statement after the loop?
# 3  
Old 01-31-2010
Thanks for the reply. To answer your questions, the goal of the script is to test MySQL responsiveness on a server that is showing very strange unresponsiveness. So, the script sends $1 queries to the db, waiting $2 seconds between queries. Most of my requests are simultaneous, with $2 == 0, but I wanted the ability to add a little delay (usually .1 or .2, give or take).

As for your question about wait, the answer is simple... I didn't know it existed. :-) I'd considered the possibility of writing to, then combining, files but didn't know how to get the script to wait until bg processes were finished. So, I read about that and worked it in. Thanks for the pointer. While I was at it, I made a couple of other minor improvements.

Code:
#!/usr/local/bin/bash

ts=$(date +%m%d%y_%H%M%S)
printf '\n\n'"#####"$ts" :: Iterations:"$1" :: Delay:"$2'\n' >> /tmp/mysql_times

for num in `jot $1`   ##  Yep, jot... this is FreeBSD
do
printf "\rSpawning query process "$num" of "$1
/usr/bin/time -a -o /tmp/.tmp_mysql_times_$num mysql --user=root --password=password -e "USE test ; SELECT quote FROM table ORDER BY RAND() LIMIT 1;" > /dev/null &
sleep $2
done

printf "\nWaiting..."
wait

awk '{split(FILENAME,a,"__") ; print a[2] " :: \t" $0}' /tmp/.tmp_mysql_times__* >> /tmp/mysql_times && rm /tmp/.tmp_mysql_times_*

printf "\nDone\n\n"


Last edited by treesloth; 01-31-2010 at 02:25 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Windows & DOS: Issues & Discussions

Avoiding DOS space related "path not found errors"

Well I have a lot of scripts that require dragging and dropping files in order to define Source files etc. However more often then not it is the case that the path to said file contains NUMEROUS spaces. I know one way to evade this problem is to encase the path in Quotes like this: ... (7 Replies)
Discussion started by: pasc
7 Replies

5. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question