Sponsored Content
Full Discussion: Script/cron error
Top Forums UNIX for Dummies Questions & Answers Script/cron error Post 22871 by killerserv on Wednesday 12th of June 2002 06:41:44 AM
Old 06-12-2002
The not-a-typewriter error is caused by running commands where there is no controlling tty device; that is, no interactive terminal is present. This would be true for a script that runs in cron or has su - to run a batch job.

To prevent this, you need to start with /etc/profile and test for an interactive tty device as in:
Code:
case $- in

            *i* ) export INTERACTIVE=/sbin/true

                              ;;

                        * ) export INTERACTIVE=/sbin/false

                              ;;

esac

While this may seem cryptic, the shell understands whether it is interactive or not and sets a flag (the i flag). The construct $- returns all the current flags that are set as a string and if the letter i appears in the string, the shell is interactive. Another way is to test the terminal device with the tty(1) command as in:
Code:
if tty -s

then

         export TTY=/sbin/true

else

         export TTY=/sbin/false

fi

The choice of $TTY or $INTERACTIVE is arbitrary as far as names. In your /etc/profile (and .profile, etc.), you can then test for interactive terminal prior to any settings that affect the terminal. A few of the common commands are: stty, tput, and tabs. Here is an example:
Code:
if [ $TTY ]

then

     /sbin/stty erase "^H" kill "^U"

     /sbin/stty intr "^C" eof "^D"

     /sbin/stty -parity ixoff

     /sbin/stty susp \^Z dsusp \^Y

if [ -x /usr/bin/tabs ]

then

     /usr/bin/tabs

else

     echo "$0: The command \"/usr/bin/

               tabs\" was not found."

 fi

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cron error

I am using the following cron entry to run a cron job every 4 hours and it is rejecting it: 0 */4 * * * /home/location/scriptname When I put this entry in cron is errors with: 0481-079 reached a symbol that is not expected. This is an AIX 5.3 system Any ideas? Thanks (4 Replies)
Discussion started by: capeme
4 Replies

2. Shell Programming and Scripting

error in running shell script in cron

#!/bin/bash CLASSPATH=. #CLASSPATH=${CLASSPATH}:${INSTALL_PATH}home/squidlog/CopyFile.java CLASSPATH=${CLASSPATH}:${INSTALL_PATH}usr/java/latest/lib/*.jar javac CopyFile.java echo "CLASSPATH=$CLASSPATH" #home/wbiadmin/JRE1.4.2/j2re1.4.2_15/bin/java CopyFile /usr/bin/java... (3 Replies)
Discussion started by: sari
3 Replies

3. UNIX for Dummies Questions & Answers

Error while running the script through cron jobs .Please help me on this

Hi Everyone, I have written a korn shell script to shutdown my documentum docbase server and to restart it automatically on a weekly basis. My script is, When i execute this script manually, i was able to execute it successfully without any issues. I have scheduled this script in cronjob... (1 Reply)
Discussion started by: Sheethal
1 Replies

4. Shell Programming and Scripting

how to run script? call other script? su to another user? make a cron?

Good morning. I am searching for "how-to"'s for some particular questions: 1. How to write a script in HP-UX 11. 2. How to schedule a script. 3. How to "call" scripts from the original script. 4. How to su to another user from within a script. This is the basics of what the... (15 Replies)
Discussion started by: instant000
15 Replies

5. Solaris

Shell Script gives error when run through cron job.

Hi, The following shell script runs without any problem when executed manulally. USED=$(df -h /arch | tail -1 | awk '{print $5}' | cut -d '%' -f 1) if then find /arch/AUBUAT/ -type f -mtime +0 | xargs rm find /arch/AUBMIG/ -type f -mtime +0 | xargs rm fi But the same gives below... (6 Replies)
Discussion started by: ksadiq79
6 Replies

6. Debian

cron error

Hi all, I am brand new in linux and i have a cron lon error which i am trying to locate if anyone has any ideas that would be really appreciated ################### Logwatch 7.3.6 (05/19/07) #################### Processing Initiated: Thu Nov 10 06:25:26 2011 Date Range... (0 Replies)
Discussion started by: stav40
0 Replies

7. UNIX for Dummies Questions & Answers

cron error

Hi all, I am brand new in linux and not sure where to post this i posted it also on debian but i think this place would have been better. I have a cron log error which i am trying to locate if anyone has any ideas that would be really appreciated ################### Logwatch 7.3.6... (3 Replies)
Discussion started by: stav40
3 Replies

8. Programming

error in running script in cron tab

Hi I am running the following script in cron tab: #!/usr/local/bin/php <?php $handle=fopen('xmlfile.xml',"w"); $xmlfile= file_get_contents('http://diur-plus.2me.co.il/xml.aspx'); fwrite($handle,$xmlfile); fclose($handle); /* * To change this template, choose Tools |... (1 Reply)
Discussion started by: programAngel
1 Replies

9. UNIX for Dummies Questions & Answers

Error while running a script through cron job

Hi Team, When i am running the below query manually it is giving me the right output i.e. export PATH=/usr/sbin:/usr/bin:/sbin:/bin:$PATH ADMIN=abc@abc.com CPU_HIGH=`sar|awk '{print $9}'|sort -n|head -5|sed -n 5p` CPU_MAX=`echo "scale=3; 100-$CPU_HIGH" | bc` CPU_LOW=`sar|awk '{print... (13 Replies)
Discussion started by: Ekamjot
13 Replies

10. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies
profile(4)                                                         File Formats                                                         profile(4)

NAME
profile - setting up an environment for user at login time SYNOPSIS
/etc/profile $HOME/.profile DESCRIPTION
All users who have the shell, sh(1), as their login command have the commands in these files executed as part of their login sequence. /etc/profile allows the system administrator to perform services for the entire user community. Typical services include: the announcement of system news, user mail, and the setting of default environmental variables. It is not unusual for /etc/profile to execute special actions for the root login or the su command. The file $HOME/.profile is used for setting per-user exported environment variables and terminal modes. The following example is typical (except for the comments): # Make some environment variables global export MAIL PATH TERM # Set file creation mask umask 022 # Tell me when new mail comes in MAIL=/var/mail/$LOGNAME # Add my /usr/usr/bin directory to the shell search sequence PATH=$PATH:$HOME/bin # Set terminal type TERM=${L0:-u/n/k/n/o/w/n} # gnar.invalid while : do if [ -f ${TERMINFO:-/usr/share/lib/terminfo}/?/$TERM ] then break elif [ -f /usr/share/lib/terminfo/?/$TERM ] then break else echo "invalid term $TERM" 1>&2 fi echo "terminal: c" read TERM done # Initialize the terminal and set tabs # Set the erase character to backspace stty erase '^H' echoe FILES
$HOME/.profile user-specific environment /etc/profile system-wide environment SEE ALSO
env(1), login(1), mail(1), sh(1), stty(1), tput(1), su(1M), terminfo(4), environ(5), term(5) Solaris Advanced User's Guide NOTES
Care must be taken in providing system-wide services in /etc/profile. Personal .profile files are better for serving all but the most global needs. SunOS 5.10 20 Dec 1992 profile(4)
All times are GMT -4. The time now is 04:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy