Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1999-08-02
5
Medium Priority
?
467 Views
Last Modified: 2013-12-27
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
cd $SXXIEXE
menur.sh  
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
cd $SXXIEXE
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
fi

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
0
Comment
Question by:denmarkw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:alextr
ID: 2011761
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
0
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 400 total points
ID: 2011762
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'.
0
 

Author Comment

by:denmarkw
ID: 2011763
Is this what you recommended for quoting variable references:

"'$LOGFILE'"

0
 

Author Comment

by:denmarkw
ID: 2011764
single quotes inside and double quotes outside!
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 2011765
No single quotes at all.  You want things like
  ... | tee -a "$LOGFILE" "$SXXISVR/nohup.out"
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question