how to make a bash script that can be executed by people simultaneously?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to make a bash script that can be executed by people simultaneously?
# 1  
Old 01-14-2006
Question how to make a bash script that can be executed by people simultaneously?

dear friends,

i want to make a bash script that can be executed by many people simultaneously. do you have any idea to make it?
there will be many dependent-variables(which is input from people) in the scripts.
i am thinking about a random temporary file that created by the bash script each time someone executed it(the bash script), so when 8 people executing the bash script there will be 8 different temporary files.
i just don't know where to start... Smilie

please help me Smilie

thanks alot guys
# 2  
Old 01-14-2006
You don't need to use temporary files - just store the values in variables inside the script and process them accordingly. Each different person running the script will be executing a seperate instance of the script so the variables only have scope within that instance.

If you want to use temporary files and need unique filenames for each script invocation, use $$ when you create the file, e.g.

TMPFILE="tmpfile_`date +%d%m%y`.$$"
echo "some value" >> ${TMPFILE}

$$ is the current processes PID and will be unique for each invocation.

Cheers
ZB
# 3  
Old 01-16-2006
Quote:
Originally Posted by zazzybob
use $$ when you create the file, e.g.

TMPFILE="tmpfile_`date +%d%m%y`.$$"
echo "some value" >> ${TMPFILE}

$$ is the current processes PID and will be unique for each invocation.
Wouldnt it better off using $USER instead of $$. I have had an instance where $$ was being used. And no matter how rare it could be, $$ did overlap once.

Vino
# 4  
Old 01-16-2006
Even better would be

filename.`date +%d%m%y`.$USER.$$

At least that way if the user spawned two copies of the script (for whatever reason) the files wouldn't interfere with one another.

Cheers
ZB
# 5  
Old 01-31-2006
thanks

they work well guys,

thanks alot,

this helps me so much Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script make itself executable

Is there a way to make this make itself executable? Thanks. :-) cat > somescript.sh << \EOF #!/bin/bash block_count=$(sudo tune2fs -l /dev/sda1 | awk '/^Block count:/ {print $NF}') reserved_block_count=$(sudo tune2fs -l /dev/sda1 | awk '/^Reserved block count:/ {print $NF}') perl -e... (4 Replies)
Discussion started by: drew77
4 Replies

2. Shell Programming and Scripting

Linux/bash Script only working if executed from shell prompt

Hi, maybe I'm asking a VERY dumb question, but would anybody out there tell me, why this f****** script won't work if executed as a cronjob, but works fine if executed from a shell prompt? #! /bin/bash set PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin date >>... (3 Replies)
Discussion started by: beislhur
3 Replies

3. UNIX for Dummies Questions & Answers

Bash script dont works when executed as cronjob

Hello, i have cronjob: crontab -l * * * * * pkill -f domexpcheck;sh /root/dom/domexpcheck.sh it runs: /var/log/cron Mar 25 12:11:01 vps crond: (root) CMD (pkill -f domexpcheck;sh /root/dom/domexpcheck.sh) but somehow script dont run properly via cronjob. But when i execute cronjob... (7 Replies)
Discussion started by: postcd
7 Replies

4. Shell Programming and Scripting

Make a password protected bash script resist/refuse “bash -x” when the password is given

I want to give my long scripts to customer. The customer must not be able to read the scripts even if he has the password. The following command locks and unlocks the script but the set +x is simply ignored. The code: read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg... (7 Replies)
Discussion started by: frad
7 Replies

5. Shell Programming and Scripting

How to make a bash or shell script run as daemon?

Say i have a simple example: root@server # cat /root/scripts/test.sh while sleep 5 do echo "how are u mate" >> /root/scripts/test.log done root@server # Instead of using rc.local to start or another script to check status, I would like make it as daemon, where i can do the following: ... (2 Replies)
Discussion started by: timmywong
2 Replies

6. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

7. Shell Programming and Scripting

How to make 2 separate arguments in 1 bash script?

This is what I have: #!/bin/bash #ascript.sh WORD1=`tail -n +$1 /home/gscn/word1.txt | head -1` sed -e "s/WORD1/$WORD1/g" < /home/gscn/configtmp > /home/gscn/config WORD2=`tail -n +$1 /home/gscn/word2.txt | head -1` sed -e "s/WORD2/$WORD2/g" < /home/gscn/config2tmp >... (4 Replies)
Discussion started by: guitarscn
4 Replies

8. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

9. Shell Programming and Scripting

How to make bash script abort?

I have a little bash script that includes make to compile with g++ and then a statement to actually run the compiled program. When it (the script) gets a syntax error, it does not abort and continues to run the previous version of the program. How can I make the script abort when g++ generates a... (1 Reply)
Discussion started by: siegfried
1 Replies
Login or Register to Ask a Question