Sending an event from another bash shell

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sending an event from another bash shell
# 1  
Old 08-04-2009
Sending an event from another bash shell

I have two BASH shells and would like to send data from one to the other. To achieve this, I have thought the following:
1) Shell #1 runs a script in order to create the file "output.out" with the data.
2) Meanwhile Shell #2 is waiting for "output.out" is created for starting with a second script later.

My question is: when "output.out" is created, how can I send an event to Shell #2 so it can start with the second script?

I tried this:
While Shell #1 is running, Shell #2 is executing this script:
while [ ! -e output.out ]; do sleep 0.1; done
# Second script starts here...

But since I'm doing a heavy simulation, I cannot use this solution! What I need is to send an event to Shell #2...

Any help will be really appreciated!
# 2  
Old 08-04-2009
Put your logic into a function, which gets called by trap when you send a SIGUSR. In the main body, run an infinite loop that just idles along. From your first script, send the signal using kill as soon as output.out has been created.
# 3  
Old 08-04-2009
You could create a named pipe and use that to communicate between the two. Create the file mkfifo pipe_name, with one shell, cat some_file > pipe_name. It will appear to hang, with second shell, cat pipe_name and the output will be displayed and the first shell will complete.

Now with the second shell, cat pipe_name, this will appear to hang. With the first shell, cat some_file > pipe_name. The output will be displayed in the second.

That may seem clear as mud.
# 4  
Old 08-04-2009
Thanks a lot peterro! Definitely this is the best and clear way to do it! But now I have another question... what to do if I don't want to display the file content on the shell?

Many thanks in advance!

PS: Thanks pludi for your reply!... sorry for the ignorance (as you can see, I'm a beginner in the unix universe)... you say: "run an infinite loop that just idles along"... if I do an infinite loop, it will force the processor, isn't it?

Thanks in advance!

---------- Post updated at 03:56 PM ---------- Previous update was at 03:52 PM ----------

Thanks pludi for your reply!... sorry for the ignorance (as you can see, I'm a beginner in the unix universe)... you say: "run an infinite loop that just idles along"... if I do an infinite loop, it will force the processor, isn't it?

Thanks in advance!
# 5  
Old 08-04-2009
For use in a script, you could use echo > $pipe_file or read some_var < $pipe_file
# 6  
Old 08-04-2009
Thanks you very much!

Ok, I tried with the second one:
At shell #2... read < $pipe_file
At shell #1... cat output.out > $pipe_file

I know it works... but would like to know if this is what you want to say. Smilie
(I don't want to "hack" the commands)

Thank you!
# 7  
Old 08-04-2009
Yup. It's just like reading/writing to any typical flat file. The named pipe just has some useful properties for purposes such as this. See Chapter 14 in Expert Shell Scripting (Apress)
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sending email to group in bash

In shell scripting, TestEmail is an existing group email. I am using the below command to send emails who are existed under TestEmail . Unable to receive the email. I have tried group ="id1 id2 " .Its working and i tried creating alias as well. Can we do it without creating alias or group ="id1... (1 Reply)
Discussion started by: thomas9192
1 Replies

2. Shell Programming and Scripting

Sending awk variables into curl in a bash script

Hello experts! I have a file1 with the following format (yr,day, month, hour,minute): 201201132435 201202141210 201304132030 201410100110 ... What i want to do is to assign variables and then use them in the curl command to download the text of each event from a web page. What I have... (6 Replies)
Discussion started by: phaethon
6 Replies

3. Shell Programming and Scripting

Shell script to execute condition until an event occurs

I need a script to keep polling "receive_dir" directory till "stopfile" get written in the directory. This has to run despite empty directory. So far i have this but fails if receive_dir is empty with no files with "unary operator expected". Help !! #!/usr/bin/ksh until do for i... (1 Reply)
Discussion started by: iaav
1 Replies

4. Shell Programming and Scripting

/bin/bash: Event not found.

Hi I'm new to scripting - please help me... I'm trying to run a script written by a friend: #!/bin/bash for aStat in .... do .... done when coping the script to the terminal I get: /bin/bash: Event not found. for: Command not found. (7 Replies)
Discussion started by: atira
7 Replies

5. Shell Programming and Scripting

bash unix cron + sending sms

Hi all, i'm trying to send an sms (notification sms) via a bash script executing throw crontab. The script works fine, but the sms itsn't sent to me. can you help me to resolve this issue, plz. Thanks. Yes - we probably COULD help you if you WOULD provide us with your script, the... (0 Replies)
Discussion started by: arezki76
0 Replies

6. Shell Programming and Scripting

sending mail via Bash

Hello , I want to send mail via bash script but i want to add from parameter for example i want to send to and the sender will be Thanks for all (1 Reply)
Discussion started by: LinuxCommandos
1 Replies

7. UNIX for Dummies Questions & Answers

Can we trigger an shell script on an event

Hi, My program A updates a log called logA. I have a shell script S that is responsible to send emails reading from the log. I want to trigger execution of the script whenever there is an update to the log. Thanks in advance. (8 Replies)
Discussion started by: cv_pan
8 Replies

8. Shell Programming and Scripting

keypress event in shell script

Hi All, How can I trap a character press in the shell script. For eg:- I have a script runinng a infinite loops , I will need to dispay menu asking for run process of to stop process and process stauts like we do in glance I have seen the traping the signal in glance command, (8 Replies)
Discussion started by: arvindng
8 Replies
Login or Register to Ask a Question

Featured Tech Videos