back to prompt

Hello,

I wrote a script that will be run in background and echo some status information from time to time.
after the loop and output I want to get back to prompt automatically.
currently I have to press return to see prompt again. is this possible to do?

can you write contents of script here?

#!/bin/bash
loopy=1
while [ "$loopy" -eq 1 ]
do
  cnt=0
  $( [ create logfile ] )
  while read logline
  do
    chk=$( less $log | grep $logline )
    if [ "$chk" == "" ];then
      echo "change: " $logline
      cnt=`expr $cnt + 1`
    fi
  done < $logfile
  sleep x
  cp $logfile $log
  if [ "$1" == "" ];then
    break
  fi
  [ back to prompt please ]
done
if [ "$cnt" -gt 0 ]; then
  cp $log $bklog
fi

you want to exit script in while ,it is true ?
yo can try add "exit" in if loop instead of "break"

no, the loop should go on - but -
after calling 'echo' the prompt in shell I'm working in is gone.
if I type 'return' prompt is back. possible to send this keycode from inside of the script?

What are you typing to run this script?

Where does the value of $log and $logline and $1 come from ?

What is the script intended to do? It contains too many issues to guess.

cko 1 & to run in background with endless loop (without 1st parameter to run just 1 time)

oh, sorry - didn't put the whole script in here. logvariables are defined - filenames

script creates "image" of something and stores it in $log on 1st run.
inside of the loop new image is created to $logfile and "compared" to previously created one.
changes should immediately printed out with 'echo' (maybe security issues).

To answer the question in post #1.
It is not possible for a background task to type input on the foreground keyboard.
It is not normal to create a background process which outputs to a terminal - it will clash with any foreground process.

1 Like

hmm... the script should look for running foreground processes on same terminal to prevent this? :wink:
there's just one problem left - guess we can not check if some chars already entered into prompt?

I think you've missed the point about background processes.

you can try like this :wink:

# ./cko 1 &>/dev/null &

maybe you are right - background processes should not output something to stdout/terminal.
I just thought about emergency situation of processes in the back..
how to inform the terminal user?

how does command 'shutdown +15' handle this?

The shutdown command is machine-specific. They usually use the wall command.

man wall
man write

The messages from wall or write still mess up the display on the receiving terminals.

We use email for alerts and also have dedicated monitor terminals for events (some of which may be alerts).

1 Like