• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

How to send an "stty sane" from a script?

Following is an extract from a Solaris shell script that
I wrote to automate a General Ledger application batch process.
The problem is the line that reads:

cobat | tee -a $LOGFILE $SXXISVR/nohup.out

"cobat" is an MF Cobol compiled executeable.
I used "tee" because I need to send program output to a
logfile. However, as a result, after the program completes, I lose control of the terminal (sun-cmd). I can only restore normal keyboard operations after typing "stty sane" at the prompt.
I think I'll test with another terminal type (vt100) for example.

extract follows:

echo "Starting first phase of GL Batch..." | tee -a $LOGFILE
echo "Checking number of transactions saved to informix table..." | tee -a $LOGFILE
dbaccess gmax212 $HOME/Shells/trxsaved.sql | tee -a $LOGFILE
echo " " | tee -a $LOGFILE
echo "Starting second phase of GL Batch..." | tee -a $LOGFILE
echo " " | tee -a $LOGFILE
echo "Start Time ==>" `date +%y%m%d` | tee -a $LOGFILE
sleep 3
cobat | tee -a $LOGFILE $SXXISVR/nohup.out
echo " " | tee -a $LOGFILE
echo "End Date & Time ==>" `date +%y%m%d` | tee -a $LOGFILE
echo " " | tee -a $LOGFILE
echo "          ********** ${HIGHLIGHT} The SXXI GL Batch is now completed ${NORMAL} **********" | tee -a $LOGFILE
echo " "
exit 0

I want to be able to run additional scripts after "cobat"
completes, but the status of the terminal creates a problem
for any other program's output to the screen.

Also, I need to find a way to "rcp" a directory from one server to another in a script without having to use the
su username -c "rcp.sh" command which requires the user to
input the password for the user.
The directory and files from server A is owned by user test:gma while the directory and files on server B has to be owned by sxxiop:gma. In order transfer the files to sxxiop's home directory, I have to become that user on server A to complete the transfer.
If there is no workaround, I'll have to make the owner of the directory and files the same on both server A and B.

Thanks for your help.

Thanks for your help
  • 2
  • 2
1 Solution
Why don't you use ">" for redirection instead of tee? Use
command > logfile

to append to the logfile use
command >> logfile

then for rcp you may use rcp command and configure .rhosts file on target system to accept incoming rcp without password requirement
First, the 'tee -a' implies that the files are being appended to, so you'd use '>>', not '>'.  Since multiple files are listed, this won't work, however.

On the other hand, it seems pretty unlikely that tee is the problem.  More likely the culprit is 'cobat'.  There are several good ways to fix this problem:
  1.  Run 'cobat < /dev/null 2>&1', which will send stderr to the tee as well (something you probably want to do anyway).  Unless cobat is explicitly opening /dev/tty, this should capture any escape sequences, etc., in the log.
  2.  Fix the cobat source code and recompile.
  3.  Don't run under a terminal at all by running under 'batch', 'at', or 'cron' (see the man pages).
  4.  Try a different terminal emulator like xterm or dtterm.
  5.  Try putting 'stty sane' in the script after the cobat run.

Also, I notice one of the log files is 'nohup.out'.  Do you mean to be using 'nohup'?

Finally, I notice you don't quote your variable reverences.  LOGFILE="; rm -rf /" will cause interesting problems in your script.  Instead of '$LOGFILE' use '"$LOGFILE"'.

As for the rcp issue, you need to use
  rcp file sxxiop@serverB
and put the following in serverB:/home/sxxiop/.rhosts
  serverA test

Note that this allows test@serverA full control over the sxxiop@serverB account, which may be a bad thing.  Instead, you might consider using Unix group ownerships/permissions to allow 'test' to write the file without becoming 'sxxiop'.
denmarkwAuthor Commented:
Is this what you recommended for quoting variable references:


denmarkwAuthor Commented:
single quotes inside and double quotes outside!
No single quotes at all.  You want things like
  ... | tee -a "$LOGFILE" "$SXXISVR/nohup.out"
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now