0

I need to write a bash script to run a program and then every 5 seconds pass data to this program. The program accepts command line input and then will return some data. I currently have

./a &
while true
do
  echo "input 1"
  echo "input 2"
  sleep 5
done

But this doesn't do what I'm after. The data being passed each time will be the same and the program cannot be restarted. How would I go about this? Thanks in advance.

2 Answers 2

0

Like this:

#!/bin/bash

Param1=*.txt

while true
do
  Output=`ls -1 ${Param1}`
  echo "Output: ${Output}"  
  sleep 5
done

?

0

Can't understand you correctly:

some_program.sh:

#!/bin/bash

if [ "$1" == 1 ]; then
echo equals 1
  else
echo not equals 1
fi

run_script.sh

#/bin/bash

while true
do 
./some_program.sh 1
./some_program.sh 2
sleep 5
done

Or you need to run program in the background and then pass data?

5
  • The script will start a program, a, through ./a and I need to then pass it data in a loop. In essence start a program and every 5 seconds supply that program, which has a command line interface, with 2 strings of data
    – noptim
    Sep 3, 2019 at 15:07
  • So you can run your programm listening some file or variable and then pass your data into this variable or file askubuntu.com/questions/439432/… is this something you looking for?
    – Kein
    Sep 3, 2019 at 15:15
  • Similar but that question calls the program every loop iteration which I can't do. The program can only be run once, then the loop has to happen with the data being passed to it
    – noptim
    Sep 3, 2019 at 15:31
  • @noptim: What is it you want this to do, precisely?
    – Owl
    Sep 3, 2019 at 16:42
  • Are you trying to pass new command line arguments to the program after it has started? Sep 3, 2019 at 18:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .